Gathering detailed insights and metrics for random-extra
Gathering detailed insights and metrics for random-extra
Gathering detailed insights and metrics for random-extra
Gathering detailed insights and metrics for random-extra
npm install random-extra
Typescript
Module System
Node Version
NPM Version
67.5
Supply Chain
55.6
Quality
75.6
Maintenance
100
Vulnerability
98.9
License
TypeScript (66.72%)
JavaScript (33.28%)
Total Downloads
41,305
Last Day
3
Last Week
15
Last Month
160
Last Year
9,365
2 Stars
388 Commits
2 Watchers
1 Branches
2 Contributors
Updated on Jan 04, 2022
Minified
Minified + Gzipped
Latest Version
5.0.2
Package Id
random-extra@5.0.2
Unpacked Size
97.08 kB
Size
20.65 kB
File Count
49
NPM Version
lerna/6.6.2/node@v20.8.0+x64 (win32)
Node Version
20.8.0
Published on
Nov 20, 2023
Cumulative downloads
Total Downloads
Last Day
200%
3
Compared to previous day
Last Week
-48.3%
15
Compared to previous week
Last Month
5.3%
160
Compared to previous month
Last Year
-41.9%
9,365
Compared to previous year
1
Seedable random number generator supporting many common distributions.
this module fork from transitive-bullshit/random, with typescript support and some other change (include breaking change)
Welcome to the most random module on npm! 😜
Wellcome send PR for more API support or performance up
df
itemByWeight
=> dfItemByWeight
)shortid
1npm install random-extra seedrandom
1import random from 'random-extra'; 2import random = require('random-extra');
.use
vs .newUse
.use
will change current random object.newUse
will create new random objectuse seedrandom for make seed-able
1import seedrandom from 'random-extra/preset/seedrandom'; 2import { seedrandom } from 'random-extra/preset/seedrandom';
when use seedrandom, srand will able use
1seedrandom.rand() // use current seed 2seedrandom.srand() // every time call srand will make new seed 3seedrandom.rand() // use new seed
other way make seedrandom
1import random from 'random-extra'; 2const seedrandom = random.newUse('seedrandom') 3 4import _seedrandom = require('seedrandom') 5 6random.newUse(_seedrandom('hello.', { entropy: true })) 7random.newUse(_seedrandom('hello.', { entropy: false })) 8 9random.newUse(_seedrandom('hello.'))
1const random = require('random-extra') 2 3// quick uniform shortcuts 4random.float(min = 0, max = 1) // uniform float in [ min, max ) 5random.int(min = 0, max = 1) // uniform integer in [ min, max ] 6random.boolean() // true or false 7 8// uniform 9random.dfUniform(min = 0, max = 1) // () => [ min, max ) 10random.dfUniformInt(min = 0, max = 1) // () => [ min, max ] 11random.dfUniformBoolean() // () => [ false, true ] 12 13// normal 14random.dfNormal(mu = 0, sigma = 1) 15random.dfLogNormal(mu = 0, sigma = 1) 16 17// bernoulli 18random.dfBernoulli(p = 0.5) 19random.dfBinomial(n = 1, p = 0.5) 20random.dfGeometric(p = 0.5) 21 22// poisson 23random.dfPoisson(lambda = 1) 24random.dfExponential(lambda = 1) 25 26// misc 27random.dfIrwinHall(n) 28random.dfBates(n) 29random.dfPareto(alpha)
For convenience, several common dfUniform samplers are exposed directly:
1random.float() // 0.2149383367670885 2random.int(0, 100) // 72 3random.boolean() // true
All distribution methods return a thunk (function with no params), which will return a series of independent, identically distributed random variables from the specified distribution.
1// create a normal distribution with default params (mu=1 and sigma=0) 2const normal = random.dfNormal() 3normal() // 0.4855465422678824 4normal() // -0.06696771815439678 5normal() // 0.7350852689834705 6 7// create a poisson distribution with default params (lambda=1) 8const poisson = random.dfPoisson() 9poisson() // 0 10poisson() // 4 11poisson() // 1
Note that returning a thunk here is more efficient when generating multiple samples from the same distribution.
You can change the underlying PRNG or its seed as follows:
1const seedrandom = require('seedrandom') 2 3// change the underlying pseudo random number generator 4// by default, Math.random is used as the underlying PRNG 5random.use(seedrandom('foobar')) 6 7// create a new independent random number generator 8const rng = random.clone('my-new-seed') 9 10// create a second independent random number generator and use a seeded PRNG 11const rng2 = random.clone(seedrandom('kittyfoo')) 12 13// replace Math.random with rng.uniform 14rng.patch() 15 16// restore original Math.random 17rng.unpatch()
Seedable random number generator supporting many common distributions.
Defaults to Math.random as its underlying pseudorandom number generator.
Type: function (rng)
rng
(Rng | function) Underlying pseudorandom number generator. (optional, default Math.random
)Distributions
Generators
Misc
Huge shoutout to Roger Combs for donating the random
npm package for this project!
Lots of inspiration from d3-random (@mbostock and @svanschooten).
Some distributions and PRNGs are ported from C++ boost::random.
MIT © Travis Fischer
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
8 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
no SAST tool detected
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-06-09
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