fast-loaded-dice-roller
fast-loaded-dice-roller copied to clipboard
Skipping final bit in flip.c
https://github.com/probsys/fast-loaded-dice-roller/blob/19d30abe421edecf25173ca4146f02109194be5f/src/c/flip.c#L14-L25
rand()
returns a random 31-bit integer packed into a 32-bit integer (whose sign bit is always zero). The positions of the extracted bits should then be 0, ..., 30. However, by setting k=30
, flip_pos = k
, and flip_pos --
, we only ever extract bits the bits at locations 0, ..., 29.
Also the code can be made more general to determine k
automatically from limits.h
and RAND_MAX
.
The lower order bits are poor quality in C, so when bumping k=31 we should change the scan order from MSB to LSB.