Re: Better use of random number generator bits?
- From: James Waldby <j-waldby@xxxxxxxx>
- Date: Mon, 06 Mar 2006 10:28:10 -0700
Ben Rudiak-Gould wrote:
DAC wrote:[in "Better use of random number genator bits?" thread]
....This is important for us because for example to shuffle a deck of cards we
are taking 51 random numbers (between 0 and 51 down to between 0 and 1).
This on average is a total of about 2880 bits to shuffle a deck (of course
there is no maximum on this number and I have encounter one situation that
took over 13,000 bits), where you should really only need log2(52!) = 226
bits to specify a specific shuffle. So at the moment we are using on average
10 times as many bits as we really need - and quantum generator modules are
expensive and soon we will need the numbers at a rate faster than we can
produce them.
You might consider the algorithm described here:
http://groups.google.com/group/comp.lang.functional/browse_frm/thread/570615e64e3e4fc0
It's multiplication- and division-free and uses very close to n*log2(n) bits
on average, which unfortunately is rather larger than log2(n!) for small n.
For n=52 it needs 299 bits, versus 52*log2(52) = 296 and log2(52!) = 226.
Following approach uses 226 bits, if I did the arithmetic
right. Create k-bit numbers (with k as in left column)
and then divide and mod to extract randoms under the sizes
shown at the right. The middle column (labeled L) is
approximate base 2 log of product of right numbers.
k L r
17 16.99 52 51 49
22 21.99 50 48 47 37
27 26.99 46 45 44 43 34
16 15.99 42 41 38
31 30.95 40 39 36 35 33 32
29 28.98 31 30 29 28 27 26
31 30.95 25 24 23 22 20 19 18
31 30.94 21 17 16 15 14 13 12 11
22 21.79 10 9 8 7 6 5 4 3 2 1
-jiw
.
- Follow-Ups:
- Re: Better use of random number generator bits?
- From: DAC
- Re: Better use of random number generator bits?
- From: David Bernier
- Re: Better use of random number generator bits?
- References:
- Better use of random number genator bits?
- From: DAC
- Re: Better use of random number genator bits?
- From: Ben Rudiak-Gould
- Better use of random number genator bits?
- Prev by Date: Re: About set definition
- Next by Date: Re: Fermat's last theorem and a counter example
- Previous by thread: Re: Better use of random number genator bits?
- Next by thread: Re: Better use of random number generator bits?
- Index(es):
Relevant Pages
|