l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2002 May 15 14:17

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] random number question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] random number question



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.

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.