@vighnesh153/random
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    Welcome to @vighnesh153/random 👋

    Version License: GPL--3.0--or--later npm

    A collection of some 'random-generation' functions

    🏠 Homepage

    Installation

    npm i -S @vighnesh153/random
    

    Usage

    Include in TS

    import { Random } from '@vighnesh153/random';
    

    Include in JS

    const { Random } = require('@vighnesh153/random');
    

    random()

    Generate a random floating point number between 0 (inclusive) and 1 (exclusive).

    const someRandomNumber = Random.random();

    randomInt(start: number, stop: number[, step: number])

    Generate a random integer between start (inclusive) and stop (exclusive) with steps of step. Default step is 1.

    // Get a random integer between 3 and 30 with steps of 5 ie., choose one of 3, 8, 13, 18, 23, 28.
    const someRandomNumber = Random.randomInt(3, 30, 5);

    randomRange(start: number, stop: number)

    Generate a random floating point between start (inclusive) and stop (exclusive).

    // Get a random floating point number between 5 and 10.
    const someRandomNumber = Random.randomInt(5, 10);

    choice(array: [])

    Get a random element from the array.

    const someRandomElement = Random.choice([1, 2, 'a', 'b']);

    shuffle(sequence: [] | string)

    Generates a random permutation of the provided sequence. Input accepted is array or string and output will be array. In case of string, each character of the string will be an element of the return array.

    const shuffledSequence = Random.choice([1, 2, 3, 4, 5]);

    sampleInt(start: number, stop: number, count: number)

    Returns an array with count elements and each element will be a random integer between start(inclusive) and stop(exclusive).

    const sampleIntegers = Random.sample(2, 10, 5);

    sample(start: number, stop: number, count: number)

    Returns an array with count elements and each element will be a random floating point number between start(inclusive) and stop(exclusive).

    const sampleNumbers = Random.choice(0.54, 8, 4);

    Author

    👤 Vighnesh Raut

    🤝 Contributing

    Contributions, issues and feature requests are welcome!
    Feel free to check issues page. You can also take a look at the contributing guide.

    Show your support

    Give a ⭐️ if this project helped you!

    Install

    npm i @vighnesh153/random

    DownloadsWeekly Downloads

    5

    Version

    1.1.0

    License

    GPL-3.0-or-later

    Unpacked Size

    52 kB

    Total Files

    27

    Last publish

    Collaborators

    • vighnesh153