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 (x31 + x3 + 1)
X0 = Seed (replaced by 1 if it is 0)
Xn = (16807 Xn-1) mod 2147483647 (n: 1 ~ 30)
Xn = Xn-31 (n: 31 ~ 33)
Xn = (Xn-3 + Xn-31) mod 4294967296 (n: 34 ~ ...)
Initial Output: X344
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;
}