Gathering detailed insights and metrics for esm-seedrandom
Gathering detailed insights and metrics for esm-seedrandom
Gathering detailed insights and metrics for esm-seedrandom
Gathering detailed insights and metrics for esm-seedrandom
npm install esm-seedrandom
Typescript
Module System
Node Version
NPM Version
94.7
Supply Chain
99.1
Quality
78.9
Maintenance
100
Vulnerability
100
License
JavaScript (91.25%)
HTML (8.75%)
Total Downloads
685,732
Last Day
3,159
Last Week
15,070
Last Month
64,659
Last Year
529,159
13 Stars
189 Commits
4 Forks
2 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.0.5-esm.2
Package Id
esm-seedrandom@3.0.5-esm.2
Unpacked Size
257.26 kB
Size
40.12 kB
File Count
60
NPM Version
10.9.0
Node Version
23.3.0
Publised On
08 Dec 2024
Cumulative downloads
Total Downloads
Last day
-7.6%
3,159
Compared to previous day
Last week
-15.5%
15,070
Compared to previous week
Last month
10.4%
64,659
Compared to previous month
Last year
342.7%
529,159
Compared to previous year
3
Explicitly seeded random number generator for JavaScript, ported to ES Modules.
Unit tested for number generator compatability with original seedrandom CommonJS NPM package.
PRNG name | Period | Author | BigCrush test results |
---|---|---|---|
prng_alea | ~2^116 | Baagøe | pass all |
prng_xor128 | 2^128-1 | Marsaglia | fail MatrixRank and LinearComp |
prng_tychei | ~2^127 | Neves/Araujo (ChaCha) | pass all |
prng_xorwow | 2^192-2^32 | Marsaglia | fail CollisionOver, SimpPoker, and LinearComp |
prng_xor4096 | 2^4096-2^32 | Brent (xorgens) | pass all |
prng_xorshift7 | 2^256-1 | Panneton/L'ecuyer | pass all |
prng_arc4 | ~2^1600 | Bau (ARC4) | unknown |
To use Johannes Baagøe's extremely fast Alea PRNG:
1// Use alea for Johannes Baagøe's clever and fast floating-point RNG. 2import {prng_alea} from 'esm-seedrandom'; 3let myrng = prng_alea('hello.'); 4 5// By default provides 32 bits of randomness in a float. 6console.log(myrng()); // Always 0.4783254903741181 for this seed and sequence 7console.log(myrng.quick()); // Always 0.8297006865032017 for this seed and sequence 8 9// Use "double" to get 56 bits of randomness. 10console.log(myrng.double()); // Always 0.4692433053279662 for this seed and sequence 11 12// Use "int32" to get a 32 bit (signed) integer. 13console.log(myrng.int32()); // Always 1350551666 for this seed and sequence
or direclty from HTML,
1<script type="module"> 2 import {prng_alea} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/alea.min.js' 3 4 let myrng = prng_alea('an example seed string') 5 6 console.log(myrng()); // Always 0.2594452982302755 for this seed and sequence 7 console.log(myrng()); // Always 0.8253263409715146 for this seed and sequence 8 console.log(myrng()); // Always 0.42280301195569336 for this seed and sequence 9 10 // Use "quick" to get only 32 bits of randomness in a float. 11 console.log(myrng.quick()); // Always 0.9045045920647681 for this seed and sequence 12 console.log(myrng.quick()); // Always 0.7626296668313444 for this seed and sequence 13 14 // Use "int32" to get a 32 bit (signed) integer 15 console.log(myrng.int32()); // Always 1157605039 for this seed and sequence 16 console.log(myrng.int32()); // Always 346379077 for this seed and sequence 17 18 console.log(myrng.double()); // Always 0.9541419381134651 for this seed and sequence 19 console.log(myrng.double()); // Always 0.7982540860513401 for this seed and sequence 20</script>
See the API docs.
From NodeJS,
1npm install esm-seedrandom
or in HTML,
1<script type='module'> 2 import {prng_alea} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/index.min.js' 3 4 // or use the individual algorithms by module 5 6 import {prng_alea} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/alea.min.js' 7 import {prng_xor128} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xor128.min.js' 8 import {prng_tychei} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/tychei.min.js' 9 import {prng_xorwow} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xorwow.min.js' 10 import {prng_xor4096} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xor4096.min.js' 11 import {prng_xorshift7} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xorshift7.min.js' 12 import {prng_arc4} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/arc4.min.js' 13</script>
1import {prng_alea} from 'esm-seedrandom'; 2 3let rng_first = prng_alea("secret-seed", {state: true}); 4let saved_state = rng_first.state() 5for (let j = 0; j < 1e5; ++j) 6 rng_first(); 7 8// later 9 10let rng_replica = prng_alea("", {state: saved_state}); 11for (let j = 0; j < 1e5; ++j) 12 rng_replica(); 13
In normal use the prng is opaque and its internal state cannot be accessed.
However, if the state
option is provided, the prng gets a state() method
that returns a plain object the can be used to reconstruct a prng later in
the same state (by passing that saved object back as the state option).
Mocha-based live unittests for reproducability and validation of state capture and restore.
In NodeJS unittests, validation of state snapshot compatability with the original seedrandom CommonJS implementation is performed.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
3 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
8 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More