Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Pseudorandom Number Generators

Standard library base pseudorandom number generators (PRNGs).

Usage

var random = require( '@stdlib/random/base' );

random

Standard library base pseudorandom number generators (PRNGs).

var rand = random;
// returns {...}

The following PRNGs are part of the base random namespace:

The following properties are attached to each exported function:

  • NAME: The generator name.
  • PRNG: The underlying pseudorandom number generator.
  • SEED: The value used to seed the PRNG.

All packages come with a .factory() method that can be used to create a seeded pseudorandom number generator in order to obtain a deterministic sequence of random numbers.

var randu = require( '@stdlib/random/base/randu' );

var rand;
var v;
var i;

// Generate pseudorandom values...
for ( i = 0; i < 100; i++ ) {
    v = randu();
}

// Generate the same pseudorandom values...
rand = randu.factory({
    'seed': randu.SEED
});
for ( i = 0; i < 100; i++ ) {
    v = rand();
}

When drawing from a probability distribution, distribution parameters can be either supplied when calling the .factory() method or at each function invocation. See the following code block for an example of draws from a normal distribution with mean one and standard deviation two.

var normal = require( '@stdlib/random/base/normal' );

var rand = normal.factory({
    'seed': 12345
});

var r = rand( 1.0, 2.0 );
// returns <number>

rand = normal.factory( 1.0, 2.0, {
    'seed': 12345
});

r = rand();
// returns <number>

Examples

var getKeys = require( '@stdlib/utils/keys' );
var random = require( '@stdlib/random/base' );

console.log( getKeys( random ) );