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

    1.0.0 • Public • Published

    @kobayami/random

    Installation

    npm install --save @kobayami/random

    Version and License

    Summary

    An LCG random number generator that resembles the behavior of java.util.Random. This means the randomInt() method of this generator will generate the same number sequence as java.util.Random.nextInt() when both are initialized with the same seed.

    The purpose of this package is to provide a random number generator that can be initialized with seeds as to create reproducible random number sequences, because JS Math.random() does not provide such a feature.

    Usage Example

    import { Random } from "@kobayami/random";
    
    const WIDTH = 640;
    const HEIGHT = 480;
    
    const rand = new Random(1923968746);
    
    function getRandomPixelPosition(): {x: number; y: number} {
        return {
            x: rand.randomInt(WIDTH),
            y: rand.randomInt(HEIGHT)
        }
    }

    See Also

    Install

    npm i @kobayami/random

    DownloadsWeekly Downloads

    23

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    9.45 kB

    Total Files

    8

    Last publish

    Collaborators

    • kobayami