Gentoo Archives: gentoo-user

From: Matti Nykyri <Matti.Nykyri@×××.fi>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: Re: Re: OT: Mapping random numbers (PRNG)
Date: Mon, 30 Jun 2014 23:48:30
Message-Id: 20140630234757.GA19131@lyseo.edu.ouka.fi
In Reply to: [gentoo-user] Re: Re: Re: OT: Mapping random numbers (PRNG) by Kai Krakow
1 On Sun, Jun 29, 2014 at 02:38:51PM +0200, Kai Krakow wrote:
2 > Matti Nykyri <matti.nykyri@×××.fi> schrieb:
3 >
4 > > That is why the possibility for 0 and 1 (after modulo 62) is twice as
5 > > large compared to all other values (2-61).
6 >
7 > Ah, now I get it.
8 >
9 > > By definition random means that the probability for every value should be
10 > > the same. So if you have 62 options and even distribution of probability
11 > > the probability for each of them is 1/62.
12 >
13 > Still, the increased probability for single elements should hit different
14 > elements each time. So for large sets it will distribute - however, I now
15 > get why it's not completely random by definition.
16
17 Usually when you need random data the quality needs to be good! Key,
18 passwords etc. For example if an attacker knows that your random number
19 generator same or the next index with double probability, he will most
20 likely crack each character with half the tries. So for each character
21 in your password the time is split in half. Again 8 character password
22 becomes 2^8 times easier to break compared to truely random data. This
23 is just an example though.
24
25 > > Try counting how of often new_index = index and new_index = (index + 1) %
26 > > 62 and new_index = (index + 2) % 62. With your algorithm the last one
27 > > should be significantly less then the first two in large sample.
28 >
29 > I will try that. It looks like a good approach.
30
31 Ok. I wrote a little library that takes random data and mathematically
32 accurately splits it into wanted data. It is attached to the mail. You
33 only need to specify the random source and the maximum number you wish
34 to see in your set. So with 5 you get everything from 0 to 5 (in total
35 of 6 elements). The library takes care of buffering. And most
36 importantly keeps probabilities equal :)
37
38 --
39 -Matti

Attachments

File name MIME type
Makefile text/plain
librng.h text/x-chdr
librng.cpp text/x-c++src
rng.cpp text/x-c++src