Re: Entropy (was Re: how to generate random negative numbers)
On Wed, Aug 12, 2009 at 04:27:09PM -0500, Ron Johnson wrote: > Does this burn through entropy faster than other methods? Probably, although since $RANDOM accesses /dev/urandom instead of /dev/random , your available entropy remains undefined in any case. As for the numerical distribution of your formula, I have no opinion. -- "Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks" -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Re: Entropy (was Re: how to generate random negative numbers)
Eric De Mund wrote: Ron, John Hasler: ] echo $(( $(( $RANDOM - $RANDOM )) % 3 )) Ron Johnson: ] Does this burn through entropy faster than other methods? Yes. Twice as fast. And, more importantly, it's mathematically incorrect. It does not have the same probability density function as: echo $(( $(($RANDOM % 5)) - 2)) To be complete, (( $(($RANDOM % 5)) - 2)) is not perfect either, but closer to perfection if $RANDOM is a true random generator. To simplify things, let's assume that the numbers we work on are 4 bits long. The possible values are: $RANDOM -> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $RANDOM % 5 -> 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 You see that 0 has a higher probability than the other values. If Max is the biggest int that can be generated by $RANDOM, and N is the number of different values we need, we should throw away any value of $RANDOM that is >= int(Max / N) * N. Just my 2 cents ;-) François. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Re: Entropy (was Re: how to generate random negative numbers)
Ron, John Hasler: ] echo $(( $(( $RANDOM - $RANDOM )) % 3 )) Ron Johnson: ] Does this burn through entropy faster than other methods? Yes. Twice as fast. And, more importantly, it's mathematically incorrect. It does not have the same probability density function as: echo $(( $(($RANDOM % 5)) - 2)) To illustrate, assuming that each $RANDOM value is uniform over {0,1,2} mod 3, here is the table of the function b-a: b +- | | 0 1 2 +-+--- |0| 0 1 2 a|1| -1 0 1 |2| -2 -1 0 5 (the number of values in {-2,-1,0,1,2}) simply doesn't divide 9 (the number of values in {0,1,2}x{0,1,2}) (Also, remember that when one adds multiple random deviates, as the number of deviates approaches infinity, the distribution approaches Gaussian. Here, with two deviates, one ends up with a "triangle" distribution.) Programmatic cleverness sometimes works, but it's a sharp knife. One must be careful not to accidentally cut oneself. Regards, Eric -- Eric De Mund | Y!: ead0002 e...@ixian.com | ICQ: 811788 -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Entropy (was Re: how to generate random negative numbers)
On 2009-08-12 16:00, John Hasler wrote: echo $(( $(( $RANDOM - $RANDOM )) % 3 )) Does this burn through entropy faster than other methods? -- Scooty Puff, Sr The Doom-Bringer -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org