From f1d669024a1ac4e3575a2524ea9293eb2c608f12 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 17 Jun 2022 07:14:29 +0900 Subject: [PATCH] mruby-random/random.c: srand to use pointer address as a seed. Utilize process randomiser which may not be provided by non Linux OSes. With those OSes, rand() would return same values if the processes are invoked within a second. --- mrbgems/mruby-random/src/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index 6d234a120..a3e899b26 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -205,7 +205,7 @@ random_m_srand(mrb_state *mrb, mrb_value self) rand_state *t = random_ptr(self); if (mrb_get_args(mrb, "|i", &i) == 0) { - seed = (uint32_t)time(NULL) + rand_uint32(t); + seed = (uint32_t)time(NULL) ^ rand_uint32(t) ^ (uint32_t)t; } else { seed = (uint32_t)i;