You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/random/base/xorshift/README.md
+24-23Lines changed: 24 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
@license Apache-2.0
4
4
5
-
Copyright (c) 2018 The Stdlib Authors.
5
+
Copyright (c) 2025 The Stdlib Authors.
6
6
7
7
Licensed under the Apache License, Version 2.0 (the "License");
8
8
you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ limitations under the License.
20
20
21
21
# XORSHIFT
22
22
23
-
> A linear congruential pseudorandom number generator ([LCG][lcg]) based on Park and Miller.
23
+
> A 32-bit xorshift pseudorandom number generator ([XORSHIFT][xorshift]) based on George Marsaglia.
24
24
25
25
<sectionclass="usage">
26
26
@@ -32,7 +32,7 @@ var xorshift = require( '@stdlib/random/base/xorshift' );
32
32
33
33
#### xorshift()
34
34
35
-
Returns a pseudorandom integer on the interval `[1, 2147483646]`.
35
+
Returns a pseudorandom integer on the interval `[1, 4294967295]`.
36
36
37
37
```javascript
38
38
var r =xorshift();
@@ -50,7 +50,7 @@ var r = xorshift.normalized();
50
50
51
51
#### xorshift.factory( \[options] )
52
52
53
-
Returns a linear congruential pseudorandom number generator ([LCG][lcg]).
53
+
Returns a 32-bit xorshift pseudorandom number generator ([XORSHIFT][xorshift]).
54
54
55
55
```javascript
56
56
var rand =xorshift.factory();
@@ -59,10 +59,10 @@ var rand = xorshift.factory();
59
59
The function accepts the following `options`:
60
60
61
61
-**seed**: pseudorandom number generator seed.
62
-
-**state**: an [`Int32Array`][@stdlib/array/int32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
62
+
-**state**: an [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
63
63
-**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`.
64
64
65
-
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]`
65
+
By default, a random integer is used to seed the returned generator. To seed the generator, provide either an `integer` on the interval `[1, 4294967295]`
66
66
67
67
```javascript
68
68
var rand =xorshift.factory({
@@ -73,13 +73,13 @@ var r = rand();
73
73
// returns 332584831
74
74
```
75
75
76
-
or, for arbitrary length seeds, an array-like `object` containing signed 32-bit integers
76
+
or, for arbitrary length seeds, an array-like `object` containing unsigned 32-bit integers
77
77
78
78
```javascript
79
-
varInt32Array=require( '@stdlib/array/int32' );
79
+
varUint32Array=require( '@stdlib/array/uint32' );
80
80
81
81
var rand =xorshift.factory({
82
-
'seed':newInt32Array( [ 1234 ] )
82
+
'seed':newUint32Array( [ 1234 ] )
83
83
});
84
84
85
85
var r =rand();
@@ -234,8 +234,8 @@ var o = xorshift.toJSON();
234
234
235
235
## Notes
236
236
237
-
- The generator has a period of approximately `2.1e9` (see [Numerical Recipes in C, 2nd Edition](#references), p. 279).
238
-
-An [LCG][lcg] is fast and uses little memory. On the other hand, because the generator is a simple [linear congruential generator][lcg], the generator has recognized shortcomings. By today's PRNG standards, the generator's period is relatively short. More importantly, the "randomness quality" of the generator's output is lacking. These defects make the generator unsuitable, for example, in Monte Carlo simulations and in cryptographic applications. For more on the advantages and disadvantages of [LCGs][lcg], see [Wikipedia][pros-cons].
237
+
- The generator has a period of `2^32-1`.
238
+
-Like all [LFSR][lfsr]s, the parameters have to be chosen very carefully in order to achieve a long period. For execution in software, xorshift generators are among the fastest PRNGs, requiring very small code and state. However, they do not pass every statistical test without further refinement.
239
239
- If PRNG state is "shared" (meaning a state array was provided during PRNG creation and **not** copied) and one sets the generator state to a state array having a different length, the PRNG does **not** update the existing shared state and, instead, points to the newly provided state array. In order to synchronize PRNG output according to the new shared state array, the state array for **each** relevant PRNG must be **explicitly** set.
240
240
- If PRNG state is "shared" and one sets the generator state to a state array of the same length, the PRNG state is updated (along with the state of all other PRNGs sharing the PRNG's state array).
241
241
@@ -286,8 +286,7 @@ for ( i = 0; i < 100; i++ ) {
286
286
287
287
## References
288
288
289
-
- Park, S. K., and K. W. Miller. 1988. "Random Number Generators: Good Ones Are Hard to Find." _Communications of the ACM_ 31 (10). New York, NY, USA: ACM: 1192–1201. doi:[10.1145/63039.63042][@park:1988].
290
-
- Press, William H., Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling. 1992. _Numerical Recipes in C: The Art of Scientific Computing, Second Edition_. Cambridge University Press.
289
+
- Marsaglia, G. 2003. "Xorshift RNGs." _Journal of Statistical Software_ 8 (14). Los Angeles, CA, USA: American Statistical Association: 1–6. doi:[10.18637/jss.v008.i14][@marsaglia:2003].
291
290
292
291
</section>
293
292
@@ -301,10 +300,12 @@ for ( i = 0; i < 100; i++ ) {
301
300
302
301
## See Also
303
302
304
-
- <spanclass="package-name">[`@stdlib/random/array/xorshift`][@stdlib/random/array/xorshift]</span><spanclass="delimiter">: </span><spanclass="description">create an array containing pseudorandom numbers generated using a linear congruential pseudorandom number generator (LCG).</span>
305
-
- <spanclass="package-name">[`@stdlib/random/iter/xorshift`][@stdlib/random/iter/xorshift]</span><spanclass="delimiter">: </span><spanclass="description">create an iterator for a linear congruential pseudorandom number generator (LCG) based on Park and Miller.</span>
306
-
- <spanclass="package-name">[`@stdlib/random/streams/xorshift`][@stdlib/random/streams/xorshift]</span><spanclass="delimiter">: </span><spanclass="description">create a readable stream for a linear congruential pseudorandom number generator (LCG) based on Park and Miller.</span>
307
-
- <spanclass="package-name">[`@stdlib/random/base/xorshift-shuffle`][@stdlib/random/base/xorshift-shuffle]</span><spanclass="delimiter">: </span><spanclass="description">A linear congruential pseudorandom number generator (LCG) whose output is shuffled.</span>
303
+
<!--
304
+
- <span class="package-name">[`@stdlib/random/array/xorshift`][@stdlib/random/array/xorshift]</span><span class="delimiter">: </span><span class="description">create an array containing pseudorandom numbers generated using a 32-bit xorshift pseudorandom number generator based on George Marsaglia.</span>
305
+
- <span class="package-name">[`@stdlib/random/iter/xorshift`][@stdlib/random/iter/xorshift]</span><span class="delimiter">: </span><span class="description">create an iterator for a 32-bit xorshift pseudorandom number generator based on George Marsaglia.</span>
306
+
- <span class="package-name">[`@stdlib/random/streams/xorshift`][@stdlib/random/streams/xorshift]</span><span class="delimiter">: </span><span class="description">create a readable stream for a 32-bit xorshift pseudorandom number generator based on George Marsaglia.</span>
307
+
-->
308
+
308
309
- <spanclass="package-name">[`@stdlib/random/base/mt19937`][@stdlib/random/base/mt19937]</span><spanclass="delimiter">: </span><spanclass="description">A 32-bit Mersenne Twister pseudorandom number generator.</span>
309
310
- <spanclass="package-name">[`@stdlib/random/base/randi`][@stdlib/random/base/randi]</span><spanclass="delimiter">: </span><spanclass="description">pseudorandom numbers having integer values.</span>
310
311
@@ -316,23 +317,23 @@ for ( i = 0; i < 100; i++ ) {
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/random/base/xorshift/docs/types/index.d.ts
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
/*
2
2
* @license Apache-2.0
3
3
*
4
-
* Copyright (c) 2019 The Stdlib Authors.
4
+
* Copyright (c) 2025 The Stdlib Authors.
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
7
* you may not use this file except in compliance with the License.
@@ -95,29 +95,29 @@ interface PRNG {
95
95
}
96
96
97
97
/**
98
-
* Interface for generating pseudorandom integers on the interval `[1, 2147483646]`.
98
+
* Interface for generating pseudorandom integers on the interval `[1, 4294967295]`.
99
99
*/
100
100
interfaceNullaryFunctionextendsPRNG{
101
101
/**
102
-
* Returns a pseudorandom integer on the interval `[1, 2147483646]`.
102
+
* Returns a pseudorandom integer on the interval `[1, 4294967295]`.
103
103
*
104
104
* @returns pseudorandom number
105
105
*/
106
106
(): number;
107
107
}
108
108
109
109
/**
110
-
* Interface for generating pseudorandom integers on the interval `[1, 2147483646]`.
110
+
* Interface for generating pseudorandom integers on the interval `[1, 4294967295]`.
111
111
*/
112
112
interfaceRandomextendsPRNG{
113
113
/**
114
-
* Returns a pseudorandom integer on the interval `[1, 2147483646]`.
114
+
* Returns a pseudorandom integer on the interval `[1, 4294967295]`.
115
115
*
116
116
* ## Notes
117
117
*
118
-
* - This pseudorandom number generator (PRNG) is a linear congruential pseudorandom number generator (LCG) based on Park and Miller.
119
-
* - The generator has a period of approximately `2.1e9`.
120
-
* - An LCG is fast and uses little memory. On the other hand, because the generator is a simple LCG, the generator has recognized shortcomings. By today's PRNG standards, the generator's period is relatively short. More importantly, the "randomness quality" of the generator's output is lacking. These defects make the generator unsuitable, for example, in Monte Carlo simulations and in cryptographic applications.
118
+
* - This pseudorandom number generator (PRNG) is a 32-bit xorshift pseudorandom number generator based on George Marsaglia.
119
+
* - The generator has a period of `2^32-1`.
120
+
* - Like all LFSRs, the parameters have to be chosen very carefully in order to achieve a long period. For execution in software, xorshift generators are among the fastest PRNGs, requiring very small code and state. However, they do not pass every statistical test without further refinement.
121
121
*
122
122
* @returns pseudorandom number
123
123
*
@@ -139,7 +139,7 @@ interface Random extends PRNG {
139
139
normalized(): number;
140
140
141
141
/**
142
-
* Returns a linear congruential pseudorandom number generator (LCG).
142
+
* Returns a 32-bit xorshift pseudorandom number generator.
143
143
*
144
144
* @param options - function options
145
145
* @param options.seed - pseudorandom number generator seed
@@ -164,13 +164,13 @@ interface Random extends PRNG {
164
164
}
165
165
166
166
/**
167
-
* Returns a pseudorandom integer on the interval `[1, 2147483646]`.
167
+
* Returns a pseudorandom integer on the interval `[1, 4294967295]`.
168
168
*
169
169
* ## Notes
170
170
*
171
-
* - This pseudorandom number generator (PRNG) is a linear congruential pseudorandom number generator (LCG) based on Park and Miller.
172
-
* - The generator has a period of approximately `2.1e9`.
173
-
* - An LCG is fast and uses little memory. On the other hand, because the generator is a simple LCG, the generator has recognized shortcomings. By today's PRNG standards, the generator's period is relatively short. More importantly, the "randomness quality" of the generator's output is lacking. These defects make the generator unsuitable, for example, in Monte Carlo simulations and in cryptographic applications.
171
+
* - This pseudorandom number generator (PRNG) is a 32-bit xorshift pseudorandom number generator based on George Marsaglia.
172
+
* - The generator has a period of `2^32-1`.
173
+
* - Like all LFSRs, the parameters have to be chosen very carefully in order to achieve a long period. For execution in software, xorshift generators are among the fastest PRNGs, requiring very small code and state. However, they do not pass every statistical test without further refinement.
0 commit comments