diff options
-rw-r--r-- | apps/playlist.c | 19 |
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 | */ |
211 | void randomise_playlist( playlist_info_t *playlist, unsigned int seed ) | 211 | void 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 | |||