[vorbis-dev] fixing shuffle in ogg123

David A. Gatwood dgatwood at deepspace.mklinux.org
Mon Dec 11 09:37:03 PST 2000



On Mon, 11 Dec 2000, MC Spanky wrote:

> On 11 Dec 2000, Guillaume Cottenceau wrote:
> 
> > 
> > There is a bug in the shuffle of ogg123 which was here at least until the
> > CVS version of 3 days ago. Here's our fix: (it seems to be not perfectly
> > equiprobable but at least fixes the old one which sometimes gives two
> > times the same song and never the other song)
> 
> ...
> 
> > +	  int j = i * ((float) rand() / RAND_MAX);
> > +	  int temp = p[j]; p[j] = p[i]; p[i] = temp;
> 
> Actually, in that first line, I think you want "j = (i + 1) *
> ...".  Otherwise, for example, the last song will NEVER be the last
> command line argument.  And you may want to divide by RAND_MAX + 1, not
> plain RAND_MAX.

It's usually easier to mod than div for these purposes.  I'm not sure what
the variables are, but I'm assuming that i is the number of songs.  In
that case, why not just:

int j = rand() % i;

possibly + 1 if you are getting the names from a table indexed from 1.

Comments?
David

---------------------------------------------------------------------
                    Check out my weekly web comic:
                     http://www.techmagazine.org

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list