Re: random generator for a given period
- From: Gordon Sande <g.sande@xxxxxxxxxxxxxxxx>
- Date: Sun, 15 Feb 2009 15:41:44 GMT
On 2009-02-15 01:35:28 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@xxxxxxxxxx> said:
Allen McIntosh wrote:Andrei Alexandrescu wrote:I've looked into the problem of randomly covering an array. Given an
array of length m, generate a succession of m random indices into that
array such that the same index is never visited more than once (and consequently the entire array is visited in m steps). So what I'm looking for is a random numbers generator of a given period and with the range equal to the period.
It sounds like what you need is a random permutation. The Wikipedia article on "random permutation" should get you started.
If you are using this for anything serious, you should read
http://www.cigital.com/papers/download/developer_gambling.php
(google "computer shuffle card deck" for more)
I am familiar with shuffling via e.g. the Fisher-Yates algorithm. However I am not looking for that. The original array is supposed to remain untouched, I just need to generate a random sequence of indices to walk it. Again, a simple approach is to generate a separate array of indices and shuffle that. But I'd like to do it in constant space, e.g. by using a special random number generator.
Andrei
If you literally want a pseudo random number generator with an arbitrary user specified
length implelemented with the usual modular arithmetic you will find that things are
very awkward technically as most modulii will be composite with multiple distinct
prime factors. The usual theory covers prime or prime power modulus only as these
lead to very tractable finite groups with only a few subgoups. (That is why the
seed for use with prime power is restricted. It picks the desired subgroup!) You can
keep track of the subgroups but that requires bookkeeping that looks more like
log n space.
If development time is at all valued the use of a conventional permutation algorithm
with a marker array would seem sensible. Memory is very chearp anymore except for
folks doing rather special hardware.
.
- Follow-Ups:
- Re: random generator for a given period
- From: Andrei Alexandrescu
- Re: random generator for a given period
- References:
- random generator for a given period
- From: Andrei Alexandrescu
- Re: random generator for a given period
- From: Allen McIntosh
- Re: random generator for a given period
- From: Andrei Alexandrescu
- random generator for a given period
- Prev by Date: Re: resampling methods are serious procedure?
- Next by Date: Re: random generator for a given period
- Previous by thread: Re: random generator for a given period
- Next by thread: Re: random generator for a given period
- Index(es):
Relevant Pages
|