Class: prng

sjcl.prng

Random number generator

Constructor

new prng()

Use sjcl.random as a singleton for this class!

This random number generator is a derivative of Ferguson and Schneier's generator Fortuna. It collects entropy from various events into several pools, implemented by streaming SHA-256 instances. It differs from ordinary Fortuna in a few ways, though.

Most importantly, it has an entropy estimator. This is present because there is a strong conflict here between making the generator available as soon as possible, and making sure that it doesn't "run on empty". In Fortuna, there is a saved state file, and the system is likely to have time to warm up.

Second, because users are unlikely to stay on the page for very long, and to speed startup time, the number of pools increases logarithmically: a new pool is created when the previous one is actually used for a reseed. This gives the same asymptotic guarantees as Fortuna, but gives more entropy to early reseeds.

The entire mechanism here feels pretty klunky. Furthermore, there are several improvements that should be made, including support for dedicated cryptographic functions that may be present in some browsers; state files in local storage; cookies containing randomness; etc. So look for improvements in future versions.

Source:

Methods

_reseedFromPools(full)

reseed the data from the entropy pools
Parameters:
Name Type Description
full If set, use all the entropy pools in the reseed.
Source:

addEntropy(data, estimatedEntropy, source)

Add entropy to the pools.
Parameters:
Name Type Description
data The entropic value. Should be a 32-bit integer, array of 32-bit integers, or string
estimatedEntropy Number The estimated entropy of data, in bits
source String The source of the entropy, eg "mouse"
Source:

addEventListener()

add an event listener for progress or seeded-ness.
Source:

getProgress()

Get the generator's progress toward readiness, as a fraction
Source:

isReady()

Is the generator ready?
Source:

randomWords(nwords)

Generate several random words, and return them in an array. A word consists of 32 bits (4 bytes)
Parameters:
Name Type Description
nwords Number The number of words to generate.
Source:

removeEventListener()

remove an event listener for progress or seeded-ness
Source:

startCollectors()

start the built-in entropy collectors
Source:

stopCollectors()

stop the built-in entropy collectors
Source: