Blum Blum shub algorithm
Random number generator based on a formula using prime numbers.
How to use ?
Started by installing the package
-
In npm :
npm install blum-blum-shub
ornpm install github:algorithmsjs/blum-blum-shub
-
In yarn :
yarn add blum-blum-shub
oryarn add github:algorithmsjs/blum-blum-shub
-
In pnpm :
pnpm add blum-blum-shub
orpnpm add github:algorithmsjs/blum-blum-shub
Documentation
Formula:
Params
Name | Type |
---|---|
p | Number |
q | Number |
seed | Number |
- On JavaScript :
// Exampleconst bbs = ;const BBS = 9 15 7; let i = 0; whilei < 6 // Get the next random number console; // Get the next random bit console; i++;
- On CoffeeScript :
# Example bbs = require'blum-blum-shub'BBS = 9157 i = 0 while i < 6 # Get the next random number consolelog BBSrandomNumber # Get the next random bit consolelog BBSrandomBit i++
...
Benchmark
- randomNumber x 10,425,712 ops/sec ±0.86% (89 runs sampled)
- randomBit x 10,280,317 ops/sec ±0.92% (90 runs sampled)
- Fastest is randomNumber
Fact
Blum Blum Shub (BBS) is an algorithm capable of producing pseudo-random numbers. It was proposed in 1986 by Lenore Blum, Manuel Blum and Michael Shub1, hence its name.