Skip to content

Commit

Permalink
lcg.c: make get_rand_bits properly cope with non-multiples of 16
Browse files Browse the repository at this point in the history
(hopefully, never used or tested)
  • Loading branch information
Douglas Bagnall committed May 15, 2011
1 parent db1e242 commit 708d83d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lcg.c
Expand Up @@ -124,10 +124,11 @@ random_getrandbits(RandomObject *self, PyObject *args)
Skip low order bits, because they're crap.*/
for (i=0 ; i<bytes ; i+=2, k-=16) {
self->state = ((self->state * RAND_MUL) + RAND_ADD) & RAND_MASK;
r = self->state;
if (k < 16)
r >>= (16 - k);
bytearray[i+0] = (unsigned char) self->state;
bytearray[i+1] = (unsigned char)(self->state >> 8);
bytearray[i+0] = (unsigned char) r;
bytearray[i+1] = (unsigned char)(r >> 8);
}

/* little endian order to match bytearray assignment order */
Expand Down

0 comments on commit 708d83d

Please sign in to comment.