diff options
author | Leo Izen <leo.izen@gmail.com> | 2022-08-14 21:28:54 -0400 |
---|---|---|
committer | Leo Izen <leo.izen@gmail.com> | 2022-08-17 10:21:55 -0400 |
commit | 52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9 (patch) | |
tree | 89b68afb896b8b50a304b5bc79625775d4ba3252 /common/playlist.c | |
parent | 813164cc07124aabfbc4aa3b8f9fe33fe222c77c (diff) | |
download | mpv-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/playlist.c')
-rw-r--r-- | common/playlist.c | 3 |
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); |