@kobayami/random
v1.0.0
Published
An LCG random number generator that resembles the behavior of java.util.random
Downloads
1
Maintainers
Readme
@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)
}
}