[vox-tech] random number question

Mark K. Kim vox-tech@lists.lugod.org
Wed, 15 May 2002 13:54:21 -0700 (PDT)


On Wed, 15 May 2002 msimons@moria.simons-clan.com wrote:

>   If your goal is play each song once in a random order, I don't see why
> you don't just assign each song a random number, then sort the list
> of songs by those random numbers to get the play list order.  When the
> first play-songs pass is finished you could generate new numbers for the
> songs and resort... very simple and easy to code.  (*)

Using the above technique, you'd have to account for situations when you
generate two same random numbers.  My method works out the math in such a
way that all numbers are unique.  Not only that, you end up with numbers
exactly between 0 and N-1, where N-1 is the number of songs, which is
neat-o from the academic point of view.

>   I'm not sure that detecting a cycle is simple... if the first three
> numbers you pulled from the random number function are 13, 22, 5.  It
> does not mean that you have found a cycle the next time those numbers
> show up in that order... depending on the algorithm a the set of numbers
> could be hit X times, and there is always a chance that 13, 22, and 5
> will be hit a second time in that order without a cycle having happened.

For most random number generating algorithm, you can easily calculate how
many calls it takes to end up in a cycle (ie - INT_MAX).  Given that
information, you can keep track of how many random number requests were
made to see when the cycle will restart.

> > BTW, some people like to seed the algorithm before every generation of
> > random number.  Something about being more random...
>
>   I don't understand how this could be "more random"... in effect they
> are just applying a hash function to whatever they use as their seed.

Me neither.  I don't buy it and I don't use it.

-Mark

--
Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.