uniform distribution from a PRNG
From: aegis (aegis_at_mad.scientist.com)
Date: 01/31/05
- Next message: Willem: "Re: uniform distribution from a PRNG"
- Previous message: CTips: "Re: initialize in O(1)"
- Next in thread: Willem: "Re: uniform distribution from a PRNG"
- Reply: Willem: "Re: uniform distribution from a PRNG"
- Reply: CBFalconer: "Re: uniform distribution from a PRNG"
- Reply: Antoon Pardon: "Re: uniform distribution from a PRNG"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jan 2005 16:12:30 -0800
In my introduction to algorithms book
by Ronald Rivest and some others, they
introduce a way to permute a string by
use of a RAND function that has a uniform
distribution.
Pseudo-code
n <- length[A]
for i <- 1 to n
do swap A[i] <-> A[RANDOM(i, n)]
Now suppose I want to permute the latin alphabet.
That is, generate all possible permutations.
How do they figure that I can generate a different
uniform sequence for each permutation of the latin
alphabet such that I never encounter duplicate
permutations?
Suppose for simplicity, that I permute "abc"
that is 3! permutations
abc
bac
cab
bca
cba
acb
So I should not encounter a sequence such that
causes "abc" to permute to "bac" and then generate
that same sequence again that would permute it in
reverse order. Which would bring me right back
to "abc". A duplicate in this case.
Anyone see how this can be done? Using the pseudo-code
supplied? Any insight would be much appreciated.
Additionally, yes I am aware you can permute things
with recursion, yadda yadda but I am clearly not
after a recursive method. I'm trying to solve the
problem presented.
-- aegis
- Next message: Willem: "Re: uniform distribution from a PRNG"
- Previous message: CTips: "Re: initialize in O(1)"
- Next in thread: Willem: "Re: uniform distribution from a PRNG"
- Reply: Willem: "Re: uniform distribution from a PRNG"
- Reply: CBFalconer: "Re: uniform distribution from a PRNG"
- Reply: Antoon Pardon: "Re: uniform distribution from a PRNG"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]