// c: rb_f_srand public static IRubyObject srandCommon( ThreadContext context, IRubyObject recv, IRubyObject newSeed) { RandomType defaultRand = getDefaultRand(context); IRubyObject previousSeed = defaultRand.getSeed(); defaultRand = new RandomType(newSeed); context.runtime.setDefaultRand(defaultRand); ((RubyRandom) (context.runtime.getRandomClass()).getConstant("DEFAULT")) .setRandomType(defaultRand); return previousSeed; }
// c: random_dump @JRubyMethod(name = "marshal_dump") public IRubyObject marshal_dump(ThreadContext context) { RubyBignum state = random.getState(); RubyInteger left = (RubyInteger) RubyNumeric.int2fix(context.runtime, random.getLeft()); RubyArray dump = RubyArray.newArray(context.runtime, state, left, random.getSeed()); if (hasVariables()) { dump.syncVariables(this); } return dump; }
@JRubyMethod public IRubyObject seed(ThreadContext context) { return random.getSeed(); }