Example #1
0
 // 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;
 }
Example #2
0
 // 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;
 }
Example #3
0
 @JRubyMethod
 public IRubyObject seed(ThreadContext context) {
   return random.getSeed();
 }