Marsaglia's pseudo random number generators: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 |  | |
| 2 | 2 | ||
| 3 | 3 | ## Marsaglia's pseudo random number generators | |
| 4 | 4 | ||
| 5 | 5 | Although Free Pascal has a reasonably good pseudo random number generator (PRNG), a [[A simple implementation of the Mersenne twister|Mersenne Twister]], it is rather slow. | |
| 6 | 6 | ||
| 7 | 7 | In 1999 (and 2003), Professor George Marsaglia described a set of PRNGs with good properties that are much faster and often just as good. He was kind enough to provide sourcecode - in C - and a description of each. The XorShift PRNG from the 2003 paper is added as well. Some of these PRNGs, either stand-alone or in combination, have over time been proven to be equal or superior to either Delphi's LNG or even Free Pascal's Mersenne twister. Notably SWR, XorShift and combined e.g. SWB+KISS which has a period of 2^7700 and passes all tests for randomness. | |
| 8 | 8 | ||
| 9 | 9 | Here we present a class that encapsulates these PRNGs for 32 bit random values with a short explanation. The class contains the following PRNGs with Marsaglia's comments from his usenet post. It is extremely fast. | |
| 10 | 10 | ||
| 11 | 11 | Marsaglia describes them as follows: | |
| 12 | 12 | ||
| 13 | 13 | ### Multiply with carry | |
| 14 | 14 | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 15 | + | ```text | |
| 16 | + | The MWC generator concatenates two 16-bit multiply- | |
| 17 | + | with-carry generators, x(n)=36969x(n-1)+carry, | |
| 18 | + | y(n)=18000y(n-1)+carry mod 2^16, has period about | |
| 19 | + | 2^60 and seems to pass all tests of randomness. A | |
| 20 | + | favorite stand-alone generator---faster than KISS, | |
| 21 | + | which contains it. | |
| 22 | + | ``` | |
| 21 | 23 | ||
| 22 | 24 | ### fibonaci | |
| 23 | 25 | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 26 | + | ```text | |
| 27 | + | FIB is the classical Fibonacci sequence | |
| 28 | + | x(n)=x(n-1)+x(n-2),but taken modulo 2^32. | |
| 29 | + | Its period is 3*2^31 if one of its two seeds is odd | |
| 30 | + | and not 1 mod 8. It has little worth as a RNG by | |
| 31 | + | itself, but provides a simple and fast component for | |
| 32 | + | use in combination generators. | |
| 33 | + | The classical Fibonacci sequence mod 2^32 from FIB | |
| 34 | + | fails several tests. It is not suitable for use by | |
| 35 | + | itself, but is quite suitable for combining with | |
| 36 | + | other generators. | |
| 37 | + | ``` | |
| 34 | 38 | ||
| 35 | 39 | ### Congruential generator | |
| 36 | 40 | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 41 | + | ``` pascal | |
| 42 | + | CONG is a congruential generator with the widely used 69069 | |
| 43 | + | multiplier: x(n)=69069x(n-1)+1234567. It has period | |
| 44 | + | 2^32. The leading half of its 32 bits seem to pass | |
| 45 | + | tests, but bits in the last half are too regular. | |
| 46 | + | The last half of the bits of CONG are too regular, | |
| 47 | + | and it fails tests for which those bits play a | |
| 48 | + | significant role. CONG+FIB will also have too much | |
| 49 | + | regularity in trailing bits, as each does. But keep | |
| 50 | + | in mind that it is a rare application for which | |
| 51 | + | the trailing bits play a significant role. CONG | |
| 52 | + | is one of the most widely used generators of the | |
| 53 | + | last 30 years, as it was the system generator for | |
| 54 | + | VAX and was incorporated in several popular | |
| 55 | + | software packages, all seemingly without complaint. | |
| 56 | + | (note: this is about the same as Delphi uses) | |
| 57 | + | ``` | |
| 52 | 58 | ||
| 53 | 59 | ### four lagged Fibonaci | |
| 54 | 60 | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 61 | + | ```text | |
| 62 | + | LFIB4 is an extension of what (Marsaglia) have previously | |
| 63 | + | defined as a lagged Fibonacci generator: | |
| 64 | + | x(n)=x(n-r) op x(n-s), with the x's in a finite | |
| 65 | + | set over which there is a binary operation op, such | |
| 66 | + | as +,- on integers mod 2^32, * on odd such integers, | |
| 67 | + | exclusive-or(xor) on binary vectors. Except for | |
| 68 | + | those using multiplication, lagged Fibonacci | |
| 69 | + | generators fail various tests of randomness, unless | |
| 70 | + | the lags are very long. (See SWB below). | |
| 71 | + | To see if more than two lags would serve to overcome | |
| 72 | + | the problems of 2-lag generators using +,- or xor, I | |
| 73 | + | have developed the 4-lag generator LFIB4 using | |
| 74 | + | addition: x(n)=x(n-256)+x(n-179)+x(n-119)+x(n-55) | |
| 75 | + | mod 2^32. Its period is 2^31*(2^256-1), about 2^287, | |
| 76 | + | and it seems to pass all tests---in particular, | |
| 77 | + | those of the kind for which 2-lag generators using | |
| 78 | + | +,-,xor seem to fail. For even more confidence in | |
| 79 | + | its suitability, LFIB4 can be combined with KISS, | |
| 80 | + | with a resulting period of about 2^410: just use | |
| 81 | + | (KISS+LFIB4) in any Pascal expression. | |
| 82 | + | ``` | |
| 75 | 83 | ||
| 76 | 84 | ### 3-shift-register generator | |
| 77 | 85 | ||
| 78 | - | ||
| 79 | - | ||
| 80 | - | ||
| 81 | - | ||
| 82 | - | ||
| 83 | - | ||
| 84 | - | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 86 | + | ``` pascal | |
| 87 | + | SHR3 is a 3-shift-register generator with period | |
| 88 | + | 2^32-1. It uses y(n)=y(n-1)(I+L^17)(I+R^13)(I+L^5), | |
| 89 | + | with the y's viewed as binary vectors, L the 32x32 | |
| 90 | + | binary matrix that shifts a vector left 1, and R its | |
| 91 | + | transpose. SHR3 seems to pass all except those | |
| 92 | + | related to the binary rank test, since 32 successive | |
| 93 | + | values, as binary vectors, must be linearly | |
| 94 | + | independent, while 32 successive truly random 32-bit | |
| 95 | + | integers, viewed as binary vectors, will be linearly | |
| 96 | + | independent only about 29% of the time. | |
| 97 | + | (note: this is an ancestor of XORSHIFT (2003) and very fast) | |
| 98 | + | ``` | |
| 89 | 99 | ||
| 90 | 100 | ### Subtract with borrow | |
| 91 | 101 | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - | ||
| 106 | - | ||
| 107 | - | ||
| 108 | - | ||
| 109 | - | ||
| 110 | - | ||
| 111 | - | ||
| 112 | - | ||
| 113 | - | ||
| 114 | - | ||
| 115 | - | ||
| 116 | - | ||
| 117 | - | ||
| 118 | - | ||
| 119 | - | ||
| 102 | + | ``` pascal | |
| 103 | + | SWB is a subtract-with-borrow generator that I | |
| 104 | + | developed to give a simple method for producing | |
| 105 | + | extremely long periods: | |
| 106 | + | x(n)=x(n-222)-x(n-237)- borrow mod 2^32. | |
| 107 | + | The 'borrow' is 0, or set to 1 if computing x(n-1) | |
| 108 | + | caused overflow in 32-bit integer arithmetic. This | |
| 109 | + | generator has a very long period, 2^7098(2^480-1), | |
| 110 | + | about 2^7578. It seems to pass all tests of | |
| 111 | + | randomness, except for the Birthday Spacings test, | |
| 112 | + | which it fails badly, as do all lagged Fibonacci | |
| 113 | + | generators using +,- or xor. I would suggest | |
| 114 | + | combining SWB with KISS, MWC, SHR3, or CONG. | |
| 115 | + | KISS+SWB has period >2^7700 and is highly | |
| 116 | + | recommended. | |
| 117 | + | Subtract-with-borrow has the same local behaviour | |
| 118 | + | as lagged Fibonacci using +,-,xor---the borrow | |
| 119 | + | merely provides a much longer period. | |
| 120 | + | SWB fails the birthday spacings test, as do all | |
| 121 | + | lagged Fibonacci and other generators that merely | |
| 122 | + | combine two previous values by means of =,- or xor. | |
| 123 | + | Those failures are for a particular case: m=512 | |
| 124 | + | birthdays in a year of n=2^24 days. There are | |
| 125 | + | choices of m and n for which lags >1000 will also | |
| 126 | + | fail the test. A reasonable precaution is to always | |
| 127 | + | combine a 2-lag Fibonacci or SWB generator with | |
| 128 | + | another kind of generator, unless the generator uses | |
| 129 | + | *, for which a very satisfactory sequence of odd | |
| 130 | + | 32-bit integers results. | |
| 131 | + | ``` | |
| 120 | 132 | ||
| 121 | 133 | ### Keep it simple sir | |
| 122 | 134 | ||
| 123 | - | ||
| 124 | - | ||
| 125 | - | ||
| 126 | - | ||
| 127 | - | ||
| 128 | - | ||
| 135 | + | ```text | |
| 136 | + | The KISS generator, (Keep It Simple Stupid), is | |
| 137 | + | designed to combine the two multiply-with-carry | |
| 138 | + | generators in MWC with the 3-shift register SHR3 and | |
| 139 | + | the congruential generator CONG, using addition and | |
| 140 | + | exclusive-or. Period about 2^123. | |
| 141 | + | It is one of (Marsaglia's) favorite generators. | |
| 142 | + | ``` | |
| 129 | 143 | ||
| 130 | 144 | ### XorShift | |
| 131 | 145 | ||
| 132 | 146 | This was not in the original post, it was only published in 2003, but since it is a similar algorithm and it is of importance for its speed and properties.\ | |
| 133 | 147 | I feel it is warranted to include it here.\ | |
| 134 | 148 | It is similar to the SHR3 PRNG and is described in detail in the pdf you find in the link below. | |
| 135 | 149 | ||
| 136 | 150 | ### Implementation | |
| 137 | 151 | ||
| 138 | 152 | The class is a fully static sealed class so you do not have to instantiate it or derive from it. If you use just one of the PRNGs it is easy to factor it out. Note that several Prng's maintain state: | |
| 139 | 153 | ||
| 140 | 154 | Here I have implemented it as a static class, but it is also possible to write them as a function with writable typed constants. I would recommend the static class approach, though, since calling the class constructor can reset the PRNG, Something that is not (easily) possible with the functional approach unless you would use global variables or double the state fields. Note that if you assign the output to a signed integer, you will get signed result, if needed. | |
| 141 | 155 | ||
| 142 | 156 | ``` pascal | |
| 143 | 157 | unit uMarsaglia; | |
| 144 | 158 | { author: Thaddy de Koning, based on the original C sourcecode in the original post by George Marsaglia } | |
| 145 | 159 | { http://www.ciphersbyritter.com/NEWS4/RANDC.HTM#369B5E30.65A55FD1@stat.fsu.edu } | |
| 146 | 160 | {$mode objfpc} | |
| 147 | 161 | interface | |
| 148 | 162 | ||
| 149 | 163 | type | |
| 150 | 164 | { It is not meant to be extended, since it is based on a single article so I sealed the class } | |
| 151 | 165 | TMarsagliaPrngs = class sealed | |
| 152 | 166 | strict private | |
| 153 | 167 | {static variables:} | |
| 154 | 168 | class var T: array [0..255] of dword; | |
| 155 | 169 | class var a,b,v,w,x,y,z,bro,jcong,jsr:dword; | |
| 156 | 170 | class var c:byte; | |
| 157 | 171 | class function wnew:dword;inline;static; | |
| 158 | 172 | class function znew:dword;inline;static; | |
| 159 | 173 | public | |
| 160 | 174 | { You can also call the create explicitly to reset the static | |
| 161 | 175 | variables.} | |
| 162 | 176 | class constructor create; | |
| 163 | 177 | class procedure settable(const i1,i2,i3,i4,i5,i6:dword);static; | |
| 164 | 178 | class procedure Randomize;inline;static; | |
| 165 | 179 | class function MWC:dword;inline;static; | |
| 166 | 180 | class function SHR3:dword;inline;static; | |
| 167 | 181 | class function CONG:dword;inline;static; | |
| 168 | 182 | class function FIB:dword;inline;static; | |
| 169 | 183 | class function KISS:dword;inline;static; | |
| 170 | 184 | class function LFIB4:dword;inline;static; | |
| 171 | 185 | class function SWB:dword;inline;static; | |
| 172 | 186 | // From XSorShift Prng's, 2003 | |
| 173 | 187 | class function XOS:dword;inline;static; | |
| 174 | 188 | end; | |
| 175 | 189 | ||
| 176 | 190 | { a shorthand alias: } | |
| 177 | 191 | Prng = type TMarsagliaPrngs; | |
| 178 | 192 | ||
| 179 | 193 | { Because many simulations call for uniform | |
| 180 | 194 | random variables in 0<x<1 or -1<x<1, here's a utility function. | |
| 181 | 195 | Using Signed = false will provide a random single in range (0,1), | |
| 182 | 196 | while Signed true will provide one in range (-1,1). | |
| 183 | 197 | Simply feed it the output of one of the Prng's} | |
| 184 | 198 | function ScaleToFloat(const value:dword; Signed:Boolean=true):single;inline; | |
| 185 | 199 | ||
| 186 | 200 | ||
| 187 | 201 | implementation | |
| 188 | 202 | ||
| 189 | 203 | class function TMarsagliaPrngs.znew:dword;inline;static; | |
| 190 | 204 | begin | |
| 191 | 205 | z:=36969*(z and 65535)+(z >> 16); | |
| 192 | 206 | Result:= z; | |
| 193 | 207 | end; | |
| 194 | 208 | ||
| 195 | 209 | class function TMarsagliaPrngs.wnew:dword;inline;static; | |
| 196 | 210 | begin | |
| 197 | 211 | w:=18000*(w and 65535)+(w >> 16); | |
| 198 | 212 | Result := w; | |
| 199 | 213 | end; | |
| 200 | 214 | ||
| 201 | 215 | ||
| 202 | 216 | class constructor TMarsagliaPrngs.create; | |
| 203 | 217 | begin | |
| 204 | 218 | a:=224466889; b:=7584631;c:=0;v:=2463534242;w:=521288629;x:=0;y:=0; | |
| 205 | 219 | z:=362436069;jsr:=123456789; jcong:=380116160; | |
| 206 | 220 | settable(12345,65435,34221,12345,9983651,95746118); | |
| 207 | 221 | end; | |
| 208 | 222 | ||
| 209 | 223 | { Use random seeds to reset z,w,jsr,jcong,a,b, and the table t[256]} | |
| 210 | 224 | class procedure TMarsagliaPrngs.settable(const i1,i2,i3,i4,i5,i6:dword);inline;static; | |
| 211 | 225 | var | |
| 212 | 226 | i:integer; | |
| 213 | 227 | begin | |
| 214 | 228 | z:=i1; w:=i2; jsr:=i3; jcong:=i4; a:=i5; b:=i6; | |
| 215 | 229 | { Example procedure to set the table using KISS:} | |
| 216 | 230 | for i:=0 to 255 do t[i]:=KISS; | |
| 217 | 231 | end; | |
| 218 | 232 | ||
| 219 | 233 | class function TMarsagliaPrngs.MWC:dword;inline;static; | |
| 220 | 234 | begin | |
| 221 | 235 | Result:= (znew << 16)+wnew; | |
| 222 | 236 | end; | |
| 223 | 237 | ||
| 224 | 238 | class function TMarsagliaPrngs.SHR3:dword;inline;static; | |
| 225 | 239 | begin | |
| 226 | 240 | jsr:=jsr xor(jsr << 17); jsr:= jsr xor(jsr >> 13); jsr:=jsr xor(jsr << 5); | |
| 227 | 241 | result := jsr; | |
| 228 | 242 | end; | |
| 229 | 243 | ||
| 230 | 244 | class function TMarsagliaPrngs.CONG:dword;inline;static; | |
| 231 | 245 | begin | |
| 232 | 246 | jcong:=69069*jcong+1234567; | |
| 233 | 247 | Result := jcong; | |
| 234 | 248 | end; | |
| 235 | 249 | ||
| 236 | 250 | class function TMarsagliaPrngs.FIB:dword;inline;static; | |
| 237 | 251 | begin | |
| 238 | 252 | b:=a+b;a:=b-a; | |
| 239 | 253 | Result := a; | |
| 240 | 254 | end; | |
| 241 | 255 | ||
| 242 | 256 | class function TMarsagliaPrngs.KISS:dword;inline;static; | |
| 243 | 257 | begin | |
| 244 | 258 | Result:= (MWC xor CONG)+SHR3; | |
| 245 | 259 | end; | |
| 246 | 260 | ||
| 247 | 261 | class function TMarsagliaPrngs.LFIB4:dword;inline;static; | |
| 248 | 262 | begin | |
| 249 | 263 | inc(c); | |
| 250 | 264 | t[c]:=t[c]+t[(c+58) and 255]+t[(c+119) and 255]+t[(c+178) and 255]; | |
| 251 | 265 | Result:=t[c]; | |
| 252 | 266 | end; | |
| 253 | 267 | ||
| 254 | 268 | class function TMarsagliaPrngs.SWB:dword;inline;static; | |
| 255 | 269 | begin | |
| 256 | 270 | inc(c);bro:=ord(x<y); | |
| 257 | 271 | x:=t[(c+34) and 255]; | |
| 258 | 272 | y:=t[(c+19) and 255]+bro; | |
| 259 | 273 | t[c] := x-y; | |
| 260 | 274 | Result:= t[c]; | |
| 261 | 275 | end; | |
| 262 | 276 | ||
| 263 | 277 | class function TMarsagliaPrngs.XOS:dword;inline;static; | |
| 264 | 278 | var tmp:dword; | |
| 265 | 279 | begin | |
| 266 | 280 | tmp:=(x xor (x<<15)); | |
| 267 | 281 | x:=y; | |
| 268 | 282 | y:=z; | |
| 269 | 283 | z:=w; | |
| 270 | 284 | w:=(w xor (w>>21)) xor (tmp xor(tmp>>4)); | |
| 271 | 285 | Result := w; | |
| 272 | 286 | end; | |
| 273 | 287 | ||
| 274 | 288 | class procedure TMarsagliaPrngs.Randomize;inline;static; | |
| 275 | 289 | begin | |
| 276 | 290 | {$WARNING This is not implemented here yet, so use system.random} | |
| 277 | 291 | system.randomize; | |
| 278 | 292 | for i:=0 to 255 do t[i]:=system.random(256); | |
| 279 | 293 | end; | |
| 280 | 294 | ||
| 281 | 295 | function ScaleToFloat(const value:dword; Signed:Boolean=true):single;inline; | |
| 282 | 296 | begin | |
| 283 | 297 | case Signed of | |
| 284 | 298 | False:Result:= dword(value) * 2.328306e-10; | |
| 285 | 299 | True :Result:= longint(value) * 4.656613e-10; | |
| 286 | 300 | end; | |
| 287 | 301 | end; | |
| 288 | 302 | ||
| 289 | 303 | end. | |
| 290 | 304 | ``` | |
| 291 | 305 | ||
| 292 | 306 | ### Example | |
| 293 | 307 | ||
| 294 | 308 | The original C code contained an example, here translated to Object Pascal. It is just a proof that we get the same results as intended. | |
| 295 | 309 | ||
| 296 | 310 | ``` pascal | |
| 297 | 311 | {$mode objfpc}{$I-} | |
| 298 | 312 | { It is basically Marsaglia's C test program in Pascal } | |
| 299 | 313 | uses | |
| 300 | 314 | uMarsaglia; | |
| 301 | 315 | var | |
| 302 | 316 | i:integer; | |
| 303 | 317 | k:dword; | |
| 304 | 318 | begin | |
| 305 | 319 | // Set the table to known values, so we can verify the results. | |
| 306 | 320 | // The one million iterations per prng are not a mistake. | |
| 307 | 321 | // The whole program will finish in less than .5 seconds even on a Raspberry pi one. | |
| 308 | 322 | // Order is important: some seeds are taken from other prng's | |
| 309 | 323 | Prng.settable(12345,65435,34221,12345,9983651,95746118); | |
| 310 | 324 | for i:=1 to 1000000 do k:=Prng.LFIB4;writeln('LFIB4 ','Pass: ',k-1064612766=0); | |
| 311 | 325 | for i:=1 to 1000000 do k:=Prng.SWB; writeln('SWB ','Pass: ',k- 627749721=0); | |
| 312 | 326 | for i:=1 to 1000000 do k:=Prng.KISS; writeln('KISS ','Pass: ',k-1372460312=0); | |
| 313 | 327 | for i:=1 to 1000000 do k:=Prng.CONG; writeln('CONG ','Pass: ',k-1529210297=0); | |
| 314 | 328 | for i:=1 to 1000000 do k:=Prng.SHR3; writeln('SHR3 ','Pass: ',k-2642725982=0); | |
| 315 | 329 | for i:=1 to 1000000 do k:=Prng.MWC; writeln('MWC ','Pass: ',k- 904977562=0); | |
| 316 | 330 | for i:=1 to 1000000 do k:=Prng.FIB; writeln('FIB ','Pass: ',k-3519793928=0); | |
| 317 | 331 | for i:=1 to 1000000 do k:=Prng.XOS; writeln('XOS ','Pass: ',k-1110212780=0); | |
| 318 | 332 | // Scale to float demo | |
| 319 | 333 | for i := 0 to 9 do writeln(ScaleToFloat(Prng.SHR3):2:10); | |
| 320 | 334 | writeln('..........................'); | |
| 321 | 335 | for i := 0 to 9 do writeln(ScaleToFloat(Prng.SHR3, false):2:10); | |
| 322 | 336 | end. | |
| 323 | 337 | ``` | |
| 324 | 338 | ||
| 325 | 339 | ### Tests | |
| 326 | 340 | ||
| 327 | 341 | The above routines are tested with FIPS-140-2 and 1000 series, which is just ***indicative***. A full Dieharder test for any of them can be found on the web. | |
| 328 | 342 | ||
| 329 | 343 | Note there can always be a "failure" since statistics predict that a failure can always happen by chance. Any of the algorithms with few failures is usable. Particulary the fast KISS+SWB that passes Dieharder and XOS that is blazing fast and as good as FPC's Mersenne twister. ote you can also test against Crush/BigCrush, but that test suite is not suitable for 32 bit Prng's as per their documentation. | |
| 330 | 344 | ||
| 331 | 345 |  | |
| 332 | 346 | ||
| 333 | 347 | ### Can we have one of these as the standard random, plz? | |
| 334 | 348 | ||
| 335 | 349 | **No you can't.** | |
| 336 | 350 | ||
| 337 | 351 | Programming languages tend not to change their PRNG and Free Pascal has a good one. It is important for a programming language to have a predictable PRNG. Many software relies on that. It would break backwards compatibility if the PRNG in a programming language would change. This is not a minor, but a very major issue. E.g. many existing datasets would become untestible and unverifiable. Even if some of the prng's that are presented here are superior in speed and properties, because of the above I hope the default Random will never be replaced. And you should hope so too.. | |
| 338 | 352 | ||
| 339 | 353 | But if you need higher speed or better properties, just use one or a combination of these... | |
| 340 | 354 | ||
| 341 | 355 | ### References | |
| 342 | 356 | ||
| 343 | 357 | 1. [The original post by George Marsaglia](http://www.ciphersbyritter.com/NEWS4/RANDC.HTM#369B5E30.65A55FD1@stat.fsu.edu)\ | |
| 344 | 358 | 2. [George Marsaglia, XorShift RNG's, Journal of Statistical Software volume 8 issue 14, July 2003](http://www.jstatsoft.org/v08/i14/paper) | |
| 345 | 359 | 3. [Diehard tests](https://en.wikipedia.org/wiki/Diehard_tests) | |
| 346 | 360 | 4. [Dieharder tests homepage, diegarder available for most linux distro's](http://www.phy.duke.edu/~rgb/General/dieharder.php) | |
| 347 | 361 | 5. [FIPS-140-2](https://en.wikipedia.org/wiki/FIPS_140-2) | |
| 348 | 362 | 6. [rngtest 2, available for most linux distro's](https://wiki.archlinux.org/index.php/Rng-tools) | |
| 349 | 363 | ||
| 350 | 364 | ## See also | |
| 351 | 365 | ||
| 352 | 366 | - [[Dev random]] | |
| 353 | 367 | - [[Functions for descriptive statistics]] | |
| 354 | 368 | - [[Generating Random Numbers]] | |
| 355 | 369 | ||
| 356 | 370 | ### TODO | |
| 357 | 371 | ||
| 358 | 372 | Provide X-platform randomize (other than FPC's random) based on timer, Windows RtlGenRandom and Unix /dev/random, /dev/urandom to seed the prng's | |
| 359 | 373 | ||
| 360 | 374 | --- | |
| 361 | 375 | *From the Free Pascal wiki, page "Marsaglia's pseudo random number generators", as it stood on 2024-03-03 after a change by Thaddy, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 362 | 376 | Category: Code | |
| 363 | 377 | Category: Mathematics | |
| 364 | 378 | Category: Modelling and Simulation | |
| 365 | 379 | Category: Statistical algorithms |
