2
$\begingroup$

There is stream (sequence) of uniform random integers $x_i$, each integer in $[0,N-1]$ range, where N is not power of 2.
I need to convert it to sequence of integers [0..255] (bytes), such that uniformity in input numbers results in uniformity in output numbers. And non-uniformity in input number results in some non-uniformity in output numbers.

I am thinking about doing $L=\sum{x_i N^{i}}$ (using multiple-precision library), then representing L in base 256 (taking bytes from L in binary). Is this good ? Is there better method ?

  • 0
    Have you considered just truncating the binary representation of $x_i$ and taking only the least significant byte? That's as close as you are going to get to a uniform distribution. **No matter what transformation you use,** the sequence of bytes will not have a uniform distribution since $N$ is not a power of $2$.2012-01-11

2 Answers 2