Installations
npm install @lgcnpm/esm-seedrandom
Developer Guide
Typescript
No
Module System
ESM, UMD
Node Version
20.12.2
NPM Version
10.5.0
Score
72.2
Supply Chain
98.9
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (91.25%)
HTML (8.75%)
Developer
Download Statistics
Total Downloads
1,386
Last Day
2
Last Week
4
Last Month
9
Last Year
1,386
GitHub Statistics
13 Stars
189 Commits
4 Forks
2 Watching
2 Branches
1 Contributors
Bundle Size
4.81 kB
Minified
1.91 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.0.6
Package Id
@lgcnpm/esm-seedrandom@3.0.6
Unpacked Size
21.26 kB
Size
6.96 kB
File Count
4
NPM Version
10.5.0
Node Version
20.12.2
Publised On
24 Apr 2024
Total Downloads
Cumulative downloads
Total Downloads
1,386
Last day
0%
2
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
-78.6%
9
Compared to previous month
Last year
0%
1,386
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
esm-seedrandom
Explicitly seeded random number generator for JavaScript, ported to ES Modules.
Unit tested for number generator compatability with original seedrandom CommonJS NPM package.
- Version: 3.0.5
- Author: David Bau
- Date: 2019-09-14
- ES Modules port in 2020-12 by Shane Holloway
Demo
GitHub Pages-based Live demo
Use
Fast PRNG Algorithms
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.mjs' 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>
Docs
See the API docs.
Overview
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.mjs' 3 4 // or use the individual algorithms by module 5 6 import {prng_alea} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/alea.min.mjs' 7 import {prng_xor128} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xor128.min.mjs' 8 import {prng_tychei} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/tychei.min.mjs' 9 import {prng_xorwow} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xorwow.min.mjs' 10 import {prng_xor4096} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xor4096.min.mjs' 11 import {prng_xorshift7} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/xorshift7.min.mjs' 12 import {prng_arc4} from '//cdn.jsdelivr.net/npm/esm-seedrandom/esm/arc4.min.mjs' 13</script>
Saving & Restoring PRNG state
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).
Unit tests
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.
LICENSE (MIT)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node-ci.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/shanewholloway/js-esm-seedrandom/node-ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node-ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/shanewholloway/js-esm-seedrandom/node-ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/node-ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3.3
/10
Last Scanned on 2025-01-20
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