Shuffle
Roberto Mariottini
rmariottini at mail.com
Fri Jan 25 00:03:11 PST 2008
Walter Bright wrote:
[...]
> for (size_t i = 0; i < files.length; i++)
> {
> auto j = std.random.rand() % files.length;
> auto fromfile = files[j];
> auto tofile = std.path.join(todir, basename(fromfile));
> writefln("%s => %s", fromfile, tofile);
> std.file.copy(fromfile, tofile);
> }
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.
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.
Ciao
--
Roberto Mariottini, http://www.mariottini.net/roberto/
SuperbCalc, a free tape calculator:
http://www.mariottini.net/roberto/superbcalc/
More information about the Digitalmars-d-announce
mailing list