Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Random

Random numbers.

Usage

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

ns

Namespace containing random number functionality.

var arr = ns.normal( [ 3, 3 ], 2.0, 5.0 );
// returns <ndarray>

The namespace exports the following functions to sample and shuffle elements from an array:

The namespace contains the following functions for generating pseudorandom values drawn from probability distributions:

The namespace contains the following sub-namespaces:

  • array: pseudorandom number generator (PRNG) array creation functions.
  • base: base (i.e., lower-level) pseudorandom number generators (PRNGs).
  • iterators: pseudorandom number generator (PRNG) iterators.
  • streams: pseudorandom number generator (PRNG) streams.
  • strided: pseudorandom number generator (PRNG) strided array functions.

Examples

var logEach = require( '@stdlib/console/log-each' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ns = require( '@stdlib/random' );

// Create a function for generating arrays originating from the same state:
var random = ns.normal.factory({
    'state': ns.normal.state,
    'copy': true
});

// Generate 3 one-dimensional arrays:
var x1 = random( [ 5 ], 2.0, 5.0 );
var x2 = random( [ 5 ], 2.0, 5.0 );
var x3 = random( [ 5 ], 2.0, 5.0 );

// Print the contents:
logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) );

// Create another function for generating random arrays with the original state:
random = ns.normal.factory({
    'state': ns.normal.state,
    'copy': true
});

// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence:
var x4 = random( [ 3, 5 ], 2.0, 5.0 );

// Convert to a list of nested arrays:
var arr = ndarray2array( x4 );

// Print the contents:
console.log( '' );
logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] );