About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Usage
var minstd = require( '@stdlib/random-base-minstd' );
minstd()
Returns a pseudorandom integer on the interval [1, 2147483646]
.
var r = minstd();
minstd.normalized()
Returns a pseudorandom number on the interval [0,1)
.
var r = minstd.normalized();
minstd.factory( [options] )
Returns a linear congruential pseudorandom number generator (LCG).
var rand = minstd.factory();
The function accepts the following options
:
- seed: pseudorandom number generator seed.
- state: an
Int32Array
containing pseudorandom number generator state. If provided, the function ignores the seed
option. - copy:
boolean
indicating whether to copy a provided pseudorandom number generator state. Setting this option to false
allows sharing state between two or more pseudorandom number generators. Setting this option to true
ensures that a returned generator has exclusive control over its internal state. Default: true
.
By default, a random integer is used to seed the returned generator. To seed the generator, provide either an integer
on the interval [1, 2147483646]
var rand = minstd.factory({
'seed': 1234
});
var r = rand();
or, for arbitrary length seeds, an array-like object
containing signed 32-bit integers
var Int32Array = require( '@stdlib/array-int32' );
var rand = minstd.factory({
'seed': new Int32Array( [ 1234 ] )
});
var r = rand();
To return a generator having a specific initial state, set the generator state
option.
var rand;
var bool;
var r;
var i;
for ( i = 0; i < 1000; i++ ) {
r = minstd();
}
rand = minstd.factory({
'state': minstd.state
});
bool = ( rand() === minstd() );
minstd.NAME
The generator name.
var str = minstd.NAME;
minstd.MIN
Minimum possible value.
var min = minstd.MIN;
minstd.MAX
Maximum possible value.
var max = minstd.MAX;
minstd.seed
The value used to seed minstd()
.
var rand;
var r;
var i;
for ( i = 0; i < 100; i++ ) {
r = minstd();
}
rand = minstd.factory({
'seed': minstd.seed
});
for ( i = 0; i < 100; i++ ) {
r = rand();
}
minstd.seedLength
Length of generator seed.
var len = minstd.seedLength;
minstd.state
Writable property for getting and setting the generator state.
var r = minstd();
r = minstd();
var state = minstd.state;
r = minstd();
r = minstd();
minstd.state = state;
r = minstd();
r = minstd();
minstd.stateLength
Length of generator state.
var len = minstd.stateLength;
minstd.byteLength
Size (in bytes) of generator state.
var sz = minstd.byteLength;
minstd.toJSON()
Serializes the pseudorandom number generator as a JSON object.
var o = minstd.toJSON();
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.