- Notifications
You must be signed in to change notification settings - Fork0
Seeded random number generators for JavaScript, ported to TypeScript.
License
NotificationsYou must be signed in to change notification settings
jurerotar/ts-seedrandom
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Seeded random number generators for JavaScript, ported to TypeScript. Based onhttps://github.com/shanewholloway/js-esm-seedrandom.
npm install ts-seedrandom
Each generator includes the following methods:
quick
- Default method used. Provides 32 bits of randomness in a float. Can either be called by calling generator instance directly (ex.generator()
) or by name (ex.generator.quick()
).double
- Provides 56 bits of randomness.int32
- Providers a 32 bit (signed) integer.state
- Provides internal generator state. Used for saving and restoring states.
import{prngAlea}from'ts-seedrandom';constaleaGenerator=prngAlea('seed');constfirstValue=aleaGenerator();constsecondValue=aleaGenerator();
You also have the option of saving and restoring state of your generator.
import{prngAlea}from'ts-seedrandom';constaleaGenerator=prngAlea('seed');constfirstValue=aleaGenerator();// Return internal generator state, which you can use in other generator instancesconststate=aleaGenerator.state();// This generator starts from the same state as first generator, but runs independentlyconstsecondAleaGenerator=prngAlea('seed',state);
The following PRNG algorithms are available:
prngAlea
: Alea algorithmprngArc4
: ARC4 algorithmprngTychei
: Tyche-i algorithmprngXor128
: XorShift128 algorithmprngXor4096
: XorShift4096 algorithmprngXorshift7
: XorShift7 algorithmprngXorwow
: Xorwow algorithm
You can import and use any of these algorithms in the same way as demonstrated in the usage examples above.
About
Seeded random number generators for JavaScript, ported to TypeScript.