A pseudorandom number generator , also known as a deterministic random bit generator , is an algorithm for generating a sequence of numbers that approximates the properties of random numbers...
George Marsaglia was an American mathematician and computer scientist. He established the lattice structure of congruential random number generators in the paper "Random numbers fall mainly in the planes". This phenomenon is sometimes called the Marsaglia effect...
. They generate the next number in their sequence by repeatedly taking the exclusive or of a number with a bit shifted
Logical shift
In computer science, a logical shift is a bitwise operation that shifts all the bits of its operand. Unlike an arithmetic shift, a logical shift does not preserve a number's sign bit or distinguish a number's exponent from its mantissa; every bit in the operand is simply moved a given number of bit...
version of itself. This makes them extremely fast on modern computer architectures. They are a subclass of Linear feedback shift registers, but their simple implementation typically makes them faster and use less space.
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
Caret usually refers to the spacing symbol ^ in ASCII and other character sets. In Unicode, however, the corresponding character is , whereas the Unicode character named caret is actually a similar but lowered symbol: ....
represents the Bitwise XOR, and " << " the bit shift
Logical shift
In computer science, a logical shift is a bitwise operation that shifts all the bits of its operand. Unlike an arithmetic shift, a logical shift does not preserve a number's sign bit or distinguish a number's exponent from its mantissa; every bit in the operand is simply moved a given number of bit...
. of one xorshift algorithm is:
uint32_t xor128(void) {
static uint32_t x = 123456789;
static uint32_t y = 362436069;
static uint32_t z = 521288629;
static uint32_t w = 88675123;
uint32_t t;
t = x ^ (x << 11);
x = y; y = z; z = w;
return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}
This algorithm has a period of and it passes the Diehard tests
Diehard tests
The diehard tests are a battery of statistical tests for measuring the quality of a random number generator. They were developed by George Marsaglia over several years and first published in 1995 on a CD-ROM of random numbers.These are the tests:...
.
The first 50 numbers produced by above algorithm are:
3 701 687 786
458 299 110
2 500 872 618
3 633 119 408
516 391 518
2 377 269 574
2 599 949 379
717 229 868
137 866 584
395 339 113
1 301 295 572
1 728 310 821
3 538 670 320
1 187 274 473
2 316 753 268
4 061 953 237
2 129 415 220
448 488 982
643 481 932
934 407 046
723 553 448
3 932 869 644
449 460 396
2 728 332 712
2 381 680 799
830 734 233
2 059 906 653
544 153 312
20 906 778
795 757 459
1 755 102 565
811 349 640
338 079 0346
2 498 575 418
420 990 039
3 358 478 731
391 216 208
3 936 394 860
1 299 350 043
4 150 927 415
1 799 713 142
2 247 676 300
1 547 958 642
4 203 610 453
3 120 566 707
4 181 181 390
3 137 093 107
821 167 952
2 328 167 796
3 450 572 369
External links
The source of this article is wikipedia, the free encyclopedia. The text of this article is licensed under the GFDL.