A reliable pseudo random number generator
npm install reliable-randomreliable-randomThis is an implementation of the PCG PRNG in
typescript. The advantages of this generator are outlined in more detail on
their website, but here
are a few:
- Excellent statistical quality
- Challenging prediction difficulty
- Reproducible results (great for sharing!)
- Multiple streams
- Arbitrary period
```
yarn install reliable-random
The main draw for this package is the ability to produce random numbers from a
user-defined seed.
The PCG implementation also allows multiple different streams of random numbers
from the same seed. This can be very helpful when creating games with a random
element to them (roguelike
games for
example) because the seeds can easily be shared with others.
The generator requires two values:
- initState: The base seed.initSequence`: The secondary seed.
-
Wht the roguelike example, the base seed may be chosen randomly (or set by the
user) and the secondary seed may be used by the developer for different sources
of randomness in the game. If the player encountered certain items on a given
seed, then they would expect the same items on a second run, even if they didn't
play the run exactly the same as the first time.
To enable this, the developer could use one random sequence for the items, and a
different random sequence for the enemies. Both of these random sequences can be
generated from the same base seed, so the user doesn't have to worry!
Another example might be in infinite world generation. It would be a problem if
the order the user generated new chunks had an influence on their randomness. In
this case, some defining feature about the chunk could be used as the second
seed, and the same chunk would always generate the same!
Check out the docs.
Made with typedoc!