[![View on NPM](https://img.shields.io/npm/v/blum-blum-shub?style=flat-square "View on NPM")](https://www.npmjs.com/package/blum-blum-shub "View on NPM") [![View on Github](https://img.shields.io/github/languages/top/algorithmsjs/blum-blum-shub?style=flat-square "View on Github")](http://https://github.com/algorithmsjs/blum-blum-shub "View on Github") [![View on Github](https://img.shields.io/github/languages/code-size/algorithmsjs/blum-blum-shub?style=flat-square "View on Github")](http://https://github.com/algorithmsjs/blum-blum-shub "View on Github")

# 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` or `npm install github:algorithmsjs/blum-blum-shub`

- In yarn :
`yarn add blum-blum-shub` or `yarn add github:algorithmsjs/blum-blum-shub`

- In pnpm :
`pnpm add blum-blum-shub` or `pnpm add github:algorithmsjs/blum-blum-shub`

## Documentation

#### Formula: [![Formula](https://wikimedia.org/api/rest_v1/media/math/render/svg/465184964d58db83481ed5258a1e32bdc8193875 "Formula")](https://en.wikipedia.org/wiki/Blum_Blum_Shub "Formula")

#### Params

|  Name  |  Type  |
| :------------: | :------------: |
|  p  | Number  |
|  q  | Number  |
|  seed  | Number  |



- On JavaScript :
```javascript
// Example
const bbs = require('blum-blum-shub');
const BBS = new bbs(9, 15, 7);

let i = 0;

while(i < 6) {
	// Get the next random number
	console.log(BBS.randomNumber());
	
	// Get the next random bit
	console.log(BBS.randomBit());
	
	i++;
}
```

- On CoffeeScript :
```coffeescript
# Example
bbs = require('blum-blum-shub')
BBS = new bbs(9, 15, 7)

 i = 0

while i < 6
	# Get the next random number
	console.log BBS.randomNumber()
	
	# Get the next random bit
	console.log BBS.randomBit()
	
	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.

###### Copyright 2020 FellGill