packetflinger / opentdm

The Quake 2 OpenTDM mod used on the PacketFlinger.com servers
GNU General Public License v2.0
12 stars 3 forks source link

Switch to custom MT19337 PRNG implementation. #10

Closed skullernet closed 4 years ago

skullernet commented 5 years ago

Original code used ‘long’ where 32-bit integers are enough. This can be a problem on LP64. Switch to custom MT19337 PRNG implementation adapted by myself from algorithm pseudo-code that is functionally equivalent but doesn't use ‘long’.

Add genrand_uniform() function that generates uniformly distributed random integers modulo N, and use it in place of naive calculations. This function uses the trick adapted from OpenBSD implementation of arc4random_uniform() to calculate 2^32 modulo N.