mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-random/random.c: randomize Random::DEFAULT.
Using time(2) and randomized pointer address. May not work well with old OSes without process randomiser.
This commit is contained in:
@@ -421,8 +421,12 @@ void mrb_mruby_random_gem_init(mrb_state *mrb)
|
||||
mrb_define_method(mrb, array, "shuffle!", mrb_ary_shuffle_bang, MRB_ARGS_OPT(1));
|
||||
mrb_define_method(mrb, array, "sample", mrb_ary_sample, MRB_ARGS_OPT(2));
|
||||
|
||||
mrb_const_set(mrb, mrb_obj_value(random), MRB_SYM(DEFAULT),
|
||||
mrb_obj_new(mrb, random, 0, NULL));
|
||||
mrb_value d = mrb_obj_new(mrb, random, 0, NULL);
|
||||
rand_state *t = random_ptr(d);
|
||||
mrb_const_set(mrb, mrb_obj_value(random), MRB_SYM(DEFAULT), d);
|
||||
|
||||
uint32_t seed = (uint32_t)time(NULL);
|
||||
rand_seed(t, seed ^ (uint32_t)t);
|
||||
}
|
||||
|
||||
void mrb_mruby_random_gem_final(mrb_state *mrb)
|
||||
|
||||
Reference in New Issue
Block a user