summaryrefslogtreecommitdiff
path: root/apps/playlist.c
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/playlist.c
parent703704d4f657db7820e4a6c9d40a22089a4b1f08 (diff)
downloadrockbox-6f75d1739fa6e1f76753a62e4417761df812c072.tar.gz
rockbox-6f75d1739fa6e1f76753a62e4417761df812c072.zip
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/playlist.c')
-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 )
210 */ 210 */
211void randomise_playlist( playlist_info_t *playlist, unsigned int seed ) 211void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
212{ 212{
213 int count = 0; 213 int count;
214 int candidate; 214 int candidate;
215 int store; 215 int store;
216 216
@@ -218,19 +218,15 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
218 srand( seed ); 218 srand( seed );
219 219
220 /* randomise entire indices list */ 220 /* randomise entire indices list */
221 221 for(count = playlist->amount - 1; count ; count--)
222 while( count < playlist->amount )
223 { 222 {
224 /* the rand is from 0 to RAND_MAX, so adjust to our value range */ 223 /* the rand is from 0 to RAND_MAX, so adjust to our value range */
225 candidate = rand() % playlist->amount; 224 candidate = rand() % (count + 1);
226 225
227 /* now swap the values at the 'count' and 'candidate' positions */ 226 /* now swap the values at the 'count' and 'candidate' positions */
228 store = playlist->indices[candidate]; 227 store = playlist->indices[candidate];
229 playlist->indices[candidate] = playlist->indices[count]; 228 playlist->indices[candidate] = playlist->indices[count];
230 playlist->indices[count] = store; 229 playlist->indices[count] = store;
231
232 /* move along */
233 count++;
234 } 230 }
235} 231}
236 232
@@ -239,12 +235,3 @@ void randomise_playlist( playlist_info_t *playlist, unsigned int seed )
239 * eval: (load-file "../firmware/rockbox-mode.el") 235 * eval: (load-file "../firmware/rockbox-mode.el")
240 * end: 236 * end:
241 */ 237 */
242
243
244
245
246
247
248
249
250