fast-loaded-dice-roller icon indicating copy to clipboard operation
fast-loaded-dice-roller copied to clipboard

Skipping final bit in flip.c

Open fsaad opened this issue 1 year ago • 1 comments

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.

fsaad avatar Feb 25 '24 00:02 fsaad

The lower order bits are poor quality in C, so when bumping k=31 we should change the scan order from MSB to LSB.

fsaad avatar Feb 25 '24 19:02 fsaad