Talk:Linear congruential generator: Difference between revisions

→‎Example Sequences: Overflow is not a problem, if you can do correct math mod 2**31.
(→‎Example Sequences: Overflow is not a problem, if you can do correct math mod 2**31.)
Line 18:
: Overflow how? Intermediate results can be done with larger integer types. --[[User:Ledrug|Ledrug]] 06:18, 8 July 2011 (UTC)
:: Sure, but in the historical implementations they probably were not done that way. In many similar systems the multiplication would exceed 2^31 and cause an integer overflow. It wouldn't produce an exception but you could suddenly be looking at a negative number. That may not yield the same sequence if you are working with large integers or 64 bit words. --[[User:Dgamey|Dgamey]] 12:28, 8 July 2011 (UTC)
 
::: If the seed is '''42''', then the first 5 numbers from BSD rand() are 1250496027, 1116302264, 1000676753, 1668674806, 908095735.
 
::: Overflow is not a problem, if you can do correct math mod 2**31. If you overflow a 32-bit integer, then the low 32 bits should be correct, so you can still take the low 31 bits as the random integer. If you overflow a 10-decimal-digit integer, then you would have a problem, because 10**10 is not a multiple of 2**31. --[[User:Kernigh|Kernigh]] 20:25, 8 July 2011 (UTC)
Anonymous user