Linux glibc default rand() (TYPE_3)
Usage
For random numbers generated using rand() from Linux.
Generator
Seed:
Seed Range
Unsigned Integer (32-bit)
Seed Size: 32 bits
Default Seed: 1
Definition
LFG / Addition (x
31 + x
3 + 1)
X
0 = Seed (replaced by 1 if it is 0)
X
n = (16807 X
n-1) mod 2147483647 (n: 1 ~ 30)
X
n = X
n-31 (n: 31 ~ 33)
X
n = (X
n-3 + X
n-31) mod 4294967296 (n: 34 ~ ...)
Initial Output: X
344
Output: X >> 1
Range: 0 ~ 2147483647
Sample Code for 100 Values (C):
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc >= 2) {
srand(atoi(argv[1]));
}
int i;
for (i = 0; i < 100; ++i){
printf("%d ", rand());
};
return 0;
}