summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorLeo Izen <leo.izen@gmail.com>2022-08-14 21:28:54 -0400
committerLeo Izen <leo.izen@gmail.com>2022-08-17 10:21:55 -0400
commit52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9 (patch)
tree89b68afb896b8b50a304b5bc79625775d4ba3252 /common
parent813164cc07124aabfbc4aa3b8f9fe33fe222c77c (diff)
downloadmpv-52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9.tar.bz2
mpv-52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9.tar.xz
misc/random: add xoshiro random number implementation
Add xoshiro as a PRNG implementation instead of relying on srand() and rand() from the C standard library. This, in particular, lets us avoid platform-defined behavior with respect to threading.
Diffstat (limited to 'common')
-rw-r--r--common/playlist.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/common/playlist.c b/common/playlist.c
index b7398dd936..21e5f63097 100644
--- a/common/playlist.c
+++ b/common/playlist.c
@@ -21,6 +21,7 @@
#include "common/common.h"
#include "common/global.h"
#include "common/msg.h"
+#include "misc/random.h"
#include "mpv_talloc.h"
#include "options/path.h"
@@ -147,7 +148,7 @@ void playlist_shuffle(struct playlist *pl)
for (int n = 0; n < pl->num_entries; n++)
pl->entries[n]->original_index = n;
for (int n = 0; n < pl->num_entries - 1; n++) {
- int j = (int)((double)(pl->num_entries - n) * rand() / (RAND_MAX + 1.0));
+ size_t j = (size_t)((pl->num_entries - n) * mp_rand_next_double());
MPSWAP(struct playlist_entry *, pl->entries[n], pl->entries[n + j]);
}
playlist_update_indexes(pl, 0, -1);