login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Output of the linear congruential pseudo-random number generator used in function rand() as described in Kernighan and Ritchie, when seeded with 0.
2

%I #32 Aug 29 2024 09:14:57

%S 0,21468,9988,22117,3498,16927,16045,19741,12122,8410,12261,27052,

%T 5659,9758,21087,25875,32368,26233,15212,17661,20496,8191,23065,23471,

%U 32096,10781,14596,23212,24244,5661,514,25643,1350,19576,8051,18234,16882,13023,5983,21166

%N Output of the linear congruential pseudo-random number generator used in function rand() as described in Kernighan and Ritchie, when seeded with 0.

%C This sequence and A061364 are generated by the same algorithm but with different seed: A061364 (as well as A096553 which is the sequence of internal states of the generator) has seed 1, while this sequence has seed 0. [Corrected by _Jean-Claude Arbaut_, Oct 05 2015]

%D Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language (Second Edition), Prentice Hall Software Series, 1988, page 46.

%H Paolo Xausa, <a href="/A096554/b096554.txt">Table of n, a(n) for n = 1..10000</a>

%H <a href="/index/Ps#PRN">Index entries for sequences related to pseudo-random numbers</a>.

%F Correction of seed value and second formula from _David Fifield_, May 23 2024: (Start)

%F x(0) = 0, x(n) = (1103515245 * x(n-1) + 12345) mod 2^31, a(n) = floor(x(n)/2^16).

%F a(n) = A061364(n + 1212780038). (End)

%t BitShiftRight[NestList[Mod[#*1103515245 + 12345, 2^31] &, 12345, 50], 16] (* _Paolo Xausa_, Aug 29 2024 *)

%o (C) static unsigned int next = 0; int rand( ) { next = next * 1103515245 + 12345; return ((next >>16) & 32767); }

%o (PARI) x(n) = if(n<1, 0, (1103515245 * x(n-1) + 12345) % (2^31));

%o vector(100, n, floor(x(n)/2^16)) \\ _Altug Alkan_, Oct 05 2015

%Y Cf. A096550-A096561 for other pseudo-random number generators.

%Y A061364 is the same generator seeded with 1.

%K nonn

%O 1,2

%A _Hugo Pfoertner_, Jul 18 2004

%E Name amended (start at 0) by _David Fifield_, May 23 2024