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:23

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, Mark K. Kim wrote:

> 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.

We are referring to linear congruential generators, right? as in,

   r_next = (p * r_last + q) % m

I am not aware of an "easy" way to determine what "N" is, given p, q, and
m. (Note that N is unlikely to be equal to m, because as soon as the
algorithm hits a number it has already generated, the sequence will
repeat.)  If you preselect those values, then N becomes predetermined.  
If you want N to correspond to the actual number of songs in a list,
determining those values at runtime becomes much more computationally
intensive than either Mike's method, or the standard "shuffle" algorithm
(iteratively pick randomly chosen songs from the unselected list of songs
until all songs have been selected).

> 
> >   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.

We must be referring to different algorithms.  Care to share?

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------

_______________________________________________
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:
Sunset Systems
Who graciously hosts our website & mailing lists!