mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user