Skip to content

Commit

Permalink
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/src/main/java/org/jruby/RubyRandom.java
Original file line number Diff line number Diff line change
@@ -758,6 +758,21 @@ public static IRubyObject newSeed(ThreadContext context, IRubyObject recv) {
return randomSeed(context.runtime);
}

@JRubyMethod(name = "raw_seed", meta = true)
public static IRubyObject rawSeed(ThreadContext context, IRubyObject recv, IRubyObject num) {
Ruby runtime = context.runtime;
int n = num.convertToInteger().getIntValue();

if (n < 0) throw runtime.newArgumentError("negative string size (or size too big)");

if (n == 0) return runtime.newString();

byte[] seed = new byte[n];
runtime.getRandom().nextBytes(seed);

return RubyString.newString(runtime, seed);
}

private void setRandomType(RandomType random) {
this.random = random;
}

0 comments on commit d66273e

Please sign in to comment.