in reply to Re^2: Music shuffling
in thread Music shuffling
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Music shuffling
by oko1 (Deacon) on Jul 08, 2008 at 17:49 UTC |