I have a prng, which generates 32-bit numbers. It has a uniform distribution. I want it to generate 8-bit numbers. When I split my 32-bit number into 4 8 bit and measure entropy of sequence, then it has something near 8 bits of entropy per byte. Sequence length is 1 mb. When I generate 8-bit numbers like this: generate_number() mod 255, and measure entropy of sequence it's like 1.7 bits per byte. I'm measuring entropy using ent How can I get random numbers of lower bitness if I have random number generator of higher bitness?

  • 1
    $\begingroup$ I don't understand your first two sentences. Does "32-bit numbers" mean integers from $0$ to $2^{32}-1$? If so, then what does "standard normal distribution" mean? What is the mean and what is the standard deviation? Isn't the PRNG producing uniformly distributed random numbers? $\endgroup$
    – Somos
    Commented Jun 4, 2020 at 13:31
  • $\begingroup$ @Somos, yes, my bad, it has a uniform ditribution $\endgroup$
    – Vladimir
    Commented Jun 4, 2020 at 15:05

1 Answer 1


Some languages use mod $256$ instead of mod $255$. In C for example the bitwise AND-operator have a maximum value of $255$ for one byte. But if you use the %-operator it takes a maximum value of $256$. Both these operators behave differently. This is not a mathematical problem, but a coders-mistake. In any case a solution might be:

generate_number() mod 256


generate_number() & 255

It depends on the programming language what these moduluses do. Having a wrong number for the modulo operation would drastically change the entropy value.

If this doesnt resolve the problem. One step is to shift-right the $32$-bit value by $8$, $16$, $24$ and so on, and check the higher order bits instead of the lower ones, if there is something strange with the lower-order bits.

Using shift-right to check other byte-regions in C: (generate_number() >> 8) mod 256 and exchange 8 with 16 or 24 et cetera for other byte regions.

We don't know enough detailed information about the Random generator you use to say whats exactly causing the entropy change. But I expect my answer is of use based on the information given.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .