From 52e7269ea633b7ac3d83d7b5cba9b15c5fbcbef9 Mon Sep 17 00:00:00 2001 From: Leo Izen Date: Sun, 14 Aug 2022 21:28:54 -0400 Subject: 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. --- common/playlist.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'common') 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); -- cgit v1.2.3