static mrb_value mrb_random_rand(mrb_state *mrb, mrb_value self) { mrb_value max; mrb_value seed; mt_state *t = mrb_mt_get_context(mrb, self); max = get_opt(mrb); seed = mrb_iv_get(mrb, self, mrb_intern2(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN)); if (mrb_nil_p(seed)) { mrb_random_mt_srand(mrb, t, mrb_nil_value()); } return mrb_random_mt_rand(mrb, t, max); }
static mrb_value mrb_random_srand(mrb_state *mrb, mrb_value self) { mrb_value seed; mrb_value old_seed; mt_state *t = mrb_mt_get_context(mrb, self); seed = get_opt(mrb); seed = mrb_random_mt_srand(mrb, t, seed); old_seed = mrb_iv_get(mrb, self, mrb_intern2(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN)); mrb_iv_set(mrb, self, mrb_intern2(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN), seed); return old_seed; }
static mrb_value mrb_random_srand(mrb_state *mrb, mrb_value self) { mrb_value seed; mrb_value old_seed; mt_state *t = mrb_mt_get_context(mrb, self); seed = get_opt(mrb); seed = mrb_random_mt_srand(mrb, t, seed); old_seed = mrb_iv_get(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY)); mrb_iv_set(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY), seed); mrb_iv_set(mrb, self, mrb_intern(mrb, MT_STATE_KEY), mrb_obj_value(Data_Wrap_Struct(mrb, mrb->object_class, &mt_state_type, (void*) t))); return old_seed; }