Gathering detailed insights and metrics for pure-random
Gathering detailed insights and metrics for pure-random
Gathering detailed insights and metrics for pure-random
Gathering detailed insights and metrics for pure-random
npm install pure-random
Typescript
Module System
Node Version
NPM Version
JavaScript (72.03%)
Shell (23.33%)
C (4.64%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
27 Stars
8 Commits
1 Forks
3 Watchers
1 Branches
1 Contributors
Updated on Nov 14, 2024
Latest Version
0.1.1
Package Id
pure-random@0.1.1
Size
6.45 kB
NPM Version
3.7.5
Node Version
5.7.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A purely functional random number generator. It implements the xorshift
algorithm. Xorshift RNGs which are a class of PRNGs that are extremely fast on modern computers and outperm other PRNGs in performance and BigCrush stress testing.
1> const rnd = require('pure-random') 2> rnd.genCsSeed() 3[ 2628481196, 1837393298, 2892949381, 1706851469 ] 4> rnd.random(rnd.genCsSeed(), 0, 10) 5Right(8)
Passing in the same seed with the same params produces the same number:
1> const seed = rnd.genCsSeed() 2> seed 3[ 426141121, 700962946, 3633913687, 2605998810 ] 4> rnd.random(seed, 0, 10) 5Right(7) 6> rnd.random(seed, 0, 10) 7Right(7) 8> rnd.random(seed, 0, 10) 9Right(7)
genSeed
1:: () -> [Uint32]
Uses Date.now
to generate a non-cryptographically secure seed. It is more performant than genCsSeed
, and appropriate for most cases. The seed is an array of four Uint32
numbers. Since there is no Uint32
in javascript yet, integers within the range [0, 4294967295] are returned.
genCsSeed
1:: () -> [Uint32]
Uses crypto.randomBytes
to generate a cryptographically secure seed. It is useful for creating an initialization vector
for cryptography, or in any situation where you need the generated random number to have significant entropy. The seed is an array of four Uint32
numbers. Since there is no Uint32
in javascript yet, integers within the range [0, 4294967295] are returned.
randUint
1:: [UInt32] -> UInt32
Takes a seed
and returns a random UInt32
value, which in javascript is an integer within the range [0, 4294967295]. This function is actually the javascript xorshift
implementation, so it is extremely fast. The other methods call this method under the hood.
randFloat
1 :: [UInt32] -> Int -> Int -> Either Error Float
Takes a seed
and a min
and max
range. It returns an Either
value that is Left Error
if the function was called with invalid parameters, or a Right Float
within the specified range (inclusive).
random
1 :: [UInt32] -> Int -> Int -> Either Error Int
Takes a seed
and a min
and max
range. It returns an Either
value that is Left Error
if the function was called with invalid parameters, or a Right Int
within the specified range (inclusive).
Math.random
is non-deterministic and doesn't have take a seed value, which means that you cannot return results consistently, which is against the purely functional paradigm. Note that this library has an option for more powerful entropy than Math.random
by using the genCsSeed
option.
The javascript number type uses a double-precision 64-bit binary format IEEE 754 value, which is a number between -(253 - 1) and 253 - 1. The xorshift* and xorshift+ libraries rely on Uint64
types, which javascript does not support. If a developer erroneously decides to represent Uint64
using the native number type, then any Uint64
type will lose precision on the upper end because a javascript number will only go up to 253 - 1 but a range of 0 to 264 - 1 is needed for Uint64
.
In general, it would be too complicated to implement these other algorithms because you would have to jump through a lot of hoops with javascript's lack of a type system, and with very little gain. These improvements to xorshift are only slightly more performant.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/8 approved changesets -- score normalized to 0
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-07-14
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