summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-07-22 15:36:39 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-07-22 15:36:39 +0000
commit6f75d1739fa6e1f76753a62e4417761df812c072 (patch)
tree292b409104bb0adb4f9caf8352c1caba2f192dc9 /apps
parent703704d4f657db7820e4a6c9d40a22089a4b1f08 (diff)
Slightly improved shuffle algorithm. Patch by Hardeep Sidhu
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1397 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/playlist.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index cac59bfd64..142f70e863 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -210,7 +210,7 @@ void add_indices_to_playlist( playlist_info_t *playlist )
*/
void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
{
- int count = 0;
+ int count;
int candidate;
int store;
@@ -218,19 +218,15 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
srand( seed );
/* randomise entire indices list */
-
- while( count < playlist->amount )
+ for(count = playlist->amount - 1; count ; count--)
{
/* the rand is from 0 to RAND_MAX, so adjust to our value range */
- candidate = rand() % playlist->amount;
+ candidate = rand() % (count + 1);
/* now swap the values at the 'count' and 'candidate' positions */
store = playlist->indices[candidate];
playlist->indices[candidate] = playlist->indices[count];
playlist->indices[count] = store;
-
- /* move along */
- count++;
}
}
@@ -239,12 +235,3 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
* eval: (load-file "../firmware/rockbox-mode.el")
* end:
*/
-
-
-
-
-
-
-
-
-