Shuffle

Walter Bright newshound1 at digitalmars.com
Fri Jan 25 01:14:26 PST 2008


Roberto Mariottini wrote:
> Here you are copying duplicate files over and over. You don't see 
> duplicates because a file copy will overwrite the previously written 
> file, but if you have enough space on the destination device you'll get 
> less files on the destination than those on the source, because 
> duplicates will overwrite.

True, the algorithm kinda sucks, but the program was created where I 
have way, way more songs on the server than will fit on the SD card. So 
even if it copies the same file multiple times, it doesn't affect the 
result (except that it takes longer).

My defense is I only spent a few minutes writing it <g>.


> I've found players that implement the shuffle function this way: the 
> pseudo random generator always "prefers" a certain subset of the songs 
> and will play them frequently, while other songs are rarely selected (if 
> ever).
> A real "shuffle" function should generate the same list of songs that 
> the source contains, changing only the order.

I agree, a much better algorithm would be to shuffle the files[] array, 
then sequentially write the shuffled result.


More information about the Digitalmars-d-announce mailing list