Wouldn't that still leave a possible collision problem at the point where the two lists join?

Which two lists? ;)

Assuming a single list of tracks:

use List::Util qw[ shuffle ]; my @tracks = shuffle readTracks( 'myMusicDB' ); while( $listening ) { push @tracks, ( my $nextTrack = shift @tracks ); play $nextTrack; }

By shuffling all your tracks once, when you load them, and then picking from the front (shifting) and replacing at the back (pushing), you are guarenteed to never hear the same track again until you've heard every other track. And you'll never know what track is coming next in any given cycle.

If your list is short and you resent being able to predict what you will hear next when the loop repeats, you could always remember the first track (post shuffle) and re-shuffle when it comes around again.

Of course that leaves you open to the possibility of hearing the same track twice in succession when you re-shuffle. Which I guess is what you mean by "two lists".

My math is pretty much limited to "arithmetic", also. That is, without I go look up the particular more advanced stuff I need for any particular thing. A side-effect of of a career of general programming as opposed to consitantly working in a particular field. A bit like a GP versus a consultant. You may cover much of the ground briefly during training, but you either use it, or loose it!


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Music shuffling by BrowserUk
in thread Music shuffling by oko1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.