Next: , Previous: , Up: random prng   [Index]


49.2.4 Generating integers in a specified range

In applications using a randomness source, it happens to need a pseudo–random integer X in a given range 0 <= X < U, while the PRNG generates a pseudo–random integer N in the range 0 <= N < M. In other words: We need a sample from the range 0 <= X < U having uniform probability distribution, by means of a sample from the range 0 <= N < M having a uniform probability distribution.

We distinguish the two cases U <= M and M < U, because when U <= M there are more integers in the range 0 <= N < M than in the range 0 <= X < U, while when M < U it is the other way around.


Next: , Previous: , Up: random prng   [Index]