Gathering detailed insights and metrics for @stdlib/random-streams-minstd-shuffle
Gathering detailed insights and metrics for @stdlib/random-streams-minstd-shuffle
Gathering detailed insights and metrics for @stdlib/random-streams-minstd-shuffle
Gathering detailed insights and metrics for @stdlib/random-streams-minstd-shuffle
Create a readable stream for a linear congruential pseudorandom number generator (LCG) whose output is shuffled.
npm install @stdlib/random-streams-minstd-shuffle
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
2 Stars
47 Commits
3 Watchers
6 Branches
14 Contributors
Updated on Apr 07, 2025
Latest Version
0.2.1
Package Id
@stdlib/random-streams-minstd-shuffle@0.2.1
Unpacked Size
101.58 kB
Size
19.76 kB
File Count
16
NPM Version
8.19.4
Node Version
16.20.2
Published on
Feb 25, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
21
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!
Create a readable stream for a linear congruential pseudorandom number generator (LCG) whose output is shuffled.
1npm install @stdlib/random-streams-minstd-shuffle
1var randomStream = require( '@stdlib/random-streams-minstd-shuffle' );
Returns a readable stream for a linear congruential pseudorandom number generator (LCG) whose output is shuffled.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3var iStream; 4var stream; 5 6function log( chunk, idx ) { 7 console.log( chunk.toString() ); 8 if ( idx === 10 ) { 9 stream.destroy(); 10 } 11} 12 13stream = randomStream(); 14iStream = inspectStream( log ); 15 16stream.pipe( iStream );
The function accepts the following options
:
false
.Buffer
objects should be decoded to strings
. Default: null
.'\n'
.boolean
indicating whether to return pseudorandom numbers on the interval [0,1)
.Int32Array
containing pseudorandom number generator state. If provided, the function ignores the seed
option.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 and/or streams. Setting this option to true
ensures that a stream generator has exclusive control over its internal state. Default: true
.1e308
.To set stream options
,
1var opts = { 2 'objectMode': true, 3 'encoding': 'utf8', 4 'highWaterMark': 64 5}; 6 7var stream = randomStream( opts );
By default, the function returns a stream which can generate an infinite number of values (i.e., the stream will never end). To limit the number of generated pseudorandom numbers, set the iter
option.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( chunk ) { 4 console.log( chunk.toString() ); 5} 6 7var opts = { 8 'iter': 10 9}; 10 11var stream = randomStream( opts ); 12var iStream = inspectStream( log ); 13 14stream.pipe( iStream );
To return pseudorandom numbers on the interval [0,1)
, set the normalized
option.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( chunk ) { 4 console.log( chunk.toString() ); 5} 6 7var opts = { 8 'iter': 10, 9 'normalized': true 10}; 11 12var stream = randomStream( opts ); 13var iStream = inspectStream( log ); 14 15stream.pipe( iStream );
By default, when not operating in objectMode, a returned stream delineates generated pseudorandom numbers using a newline character. To specify an alternative separator, set the sep
option.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( chunk ) { 4 console.log( chunk.toString() ); 5} 6 7var opts = { 8 'iter': 10, 9 'sep': ',' 10}; 11 12var stream = randomStream( opts ); 13var iStream = inspectStream( log ); 14 15stream.pipe( iStream );
To seed the underlying pseudorandom number generator, set the seed
option.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( v ) { 4 console.log( v ); 5} 6 7var opts = { 8 'objectMode': true, 9 'iter': 10, 10 'seed': 1234 11}; 12 13var stream = randomStream( opts ); 14 15opts = { 16 'objectMode': true 17}; 18var iStream = inspectStream( opts, log ); 19 20stream.pipe( iStream );
To return a readable stream with an underlying pseudorandom number generator having a specific initial state, set the state
option.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( v ) { 4 console.log( v ); 5} 6 7var opts1 = { 8 'objectMode': true, 9 'iter': 10 10}; 11 12var stream = randomStream( opts1 ); 13 14var opts2 = { 15 'objectMode': true 16}; 17var iStream = inspectStream( opts2, log ); 18 19// Stream pseudorandom numbers, thus progressing the underlying generator state: 20stream.pipe( iStream ); 21 22// Create a new PRNG stream initialized to the last state of the previous stream: 23var opts3 = { 24 'objectMode': true, 25 'iter': 10, 26 'state': stream.state 27}; 28 29stream = randomStream( opts3 ); 30iStream = inspectStream( opts2, log ); 31 32// Stream pseudorandom numbers starting from the last state of the previous stream: 33stream.pipe( iStream );
The value used to seed the underlying pseudorandom number generator.
1var stream = randomStream(); 2 3var seed = stream.seed; 4// returns <Int32Array>
Length of underlying pseudorandom number generator seed.
1var stream = randomStream(); 2 3var len = stream.seedLength; 4// returns <number>
Writable property for getting and setting the underlying pseudorandom number generator state.
1var stream = randomStream(); 2 3var state = stream.state; 4// returns <Int32Array>
Length of underlying pseudorandom number generator state.
1var stream = randomStream(); 2 3var len = stream.stateLength; 4// returns <number>
Size (in bytes) of underlying pseudorandom number generator state.
1var stream = randomStream(); 2 3var sz = stream.byteLength; 4// returns <number>
Returns a function
for creating readable streams which generate pseudorandom numbers via a linear congruential pseudorandom number generator (LCG) whose output is shuffled.
1var opts = { 2 'objectMode': true, 3 'encoding': 'utf8', 4 'highWaterMark': 64 5}; 6 7var createStream = randomStream.factory( opts );
The method accepts the same options
as randomStream()
.
This method is a convenience function to create streams which always operate in objectMode.
1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2 3function log( v ) { 4 console.log( v ); 5} 6 7var opts = { 8 'iter': 10 9}; 10var stream = randomStream.objectMode( opts ); 11 12opts = { 13 'objectMode': true 14}; 15var iStream = inspectStream( opts, log ); 16 17stream.pipe( iStream );
This method accepts the same options
as randomStream()
; however, the method will always override the objectMode
option in options
.
In addition to the standard readable stream events, the following events are supported...
Emitted after internally generating siter
pseudorandom numbers.
1var opts = { 2 'siter': 10 // emit the PRNG state every 10 pseudorandom numbers 3}; 4 5var stream = randomStream( opts ); 6 7stream.on( 'state', onState ); 8 9function onState( state ) { 10 // Do something with the emitted state, such as save to file... 11}
2.1e9
(see Numerical Recipes in C, 2nd Edition, p. 279).siter
option in conjunction with a state
event listener. Attempting to capture the underlying PRNG state after reading generated numbers is not likely to give expected results, as internal stream buffering will mean more values have been generated than have been read. Thus, the state returned by the state
property will likely reflect a future PRNG state from the perspective of downstream consumers.1var inspectStream = require( '@stdlib/streams-node-inspect-sink' ); 2var randomStream = require( '@stdlib/random-streams-minstd-shuffle' ); 3 4function log( v ) { 5 console.log( v.toString() ); 6} 7 8var opts = { 9 'objectMode': true, 10 'iter': 10 11}; 12 13var stream = randomStream( opts ); 14 15opts = { 16 'objectMode': true 17}; 18var iStream = inspectStream( opts, log ); 19 20stream.pipe( iStream );
@stdlib/random-streams-minstd-shuffle-cli
: CLI package for use as a command-line utility.@stdlib/random-base/minstd-shuffle
: A linear congruential pseudorandom number generator (LCG) whose output is shuffled.@stdlib/random-iter/minstd-shuffle
: create an iterator for a linear congruential pseudorandom number generator (LCG) whose output is shuffled.@stdlib/random-streams/minstd
: create a readable stream for a linear congruential pseudorandom number generator (LCG) based on Park and Miller.@stdlib/random-streams/mt19937
: create a readable stream for a 32-bit Mersenne Twister pseudorandom number generator.@stdlib/random-streams/randi
: create a readable stream for generating pseudorandom numbers having integer values.@stdlib/random-streams/randu
: create a readable stream for generating uniformly distributed pseudorandom numbers between 0 and 1.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.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
project is not fuzzed
Details
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More