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.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-06-17 07:14:29 +09:00
parent 267c26d20b
commit f1d669024a
+1 -1
View File
@@ -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;