Gentoo Archives: gentoo-user

From: Kai Krakow <hurikhan77@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: OT: Mapping random numbers (PRNG)
Date: Thu, 26 Jun 2014 21:16:39
Message-Id: p8eu7b-e6o.ln1@hurikhan77.spdns.de
In Reply to: Re: [gentoo-user] OT: Mapping random numbers (PRNG) by Matti Nykyri
1 Matti Nykyri <Matti.Nykyri@×××.fi> schrieb:
2
3 > If you are looking a mathematically perfect solution there is a simple
4 > one even if your list is not in the power of 2! Take 6 bits at a time of
5 > the random data. If the result is 62 or 63 you will discard the data and
6 > get the next 6 bits. This selectively modifies the random data but keeps
7 > the probabilities in correct balance. Now the probability for index of
8 > 0-61 is 1/62 because the probability to get 62-63 out of 64 if 0.
9
10 Why not do just something like this?
11
12 index = 0;
13 while (true) {
14 index = (index + get_6bit_random()) % 62;
15 output << char_array[index];
16 }
17
18 Done, no bits wasted. Should have perfect distribution also. We also don't
19 have to throw away random data just to stay within unaligned boundaries. The
20 unalignment is being taken over into the next loop so the "error" corrects
21 itself over time (it becomes distributed over the whole set).
22
23 --
24 Replies to list only preferred.

Replies

Subject Author
[gentoo-user] Re: OT: Mapping random numbers (PRNG) Kai Krakow <hurikhan77@×××××.com>
Re: [gentoo-user] Re: OT: Mapping random numbers (PRNG) Matti Nykyri <matti.nykyri@×××.fi>