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?
2026-03-27 19:30:33.1774639833
Distribution of random generator
92 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
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:
or
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 256and exchange8with16or24et 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.