RandomType(IRubyObject vseed) {
this.seed = vseed.convertToInteger();
if (seed instanceof RubyFixnum) {
long v = Math.abs(RubyNumeric.num2long(seed));
if (v == (v & 0xffffffffL)) {
this.mt = new Random((int) v);
} else {
int[] ints = new int[2];
ints[0] = (int) v;
ints[1] = (int) (v >> 32);
this.mt = new Random(ints);
}
} else if (seed instanceof RubyBignum) {
BigInteger big = ((RubyBignum) seed).getBigIntegerValue();
if (big.signum() < 0) {
big = big.abs();
}
byte[] buf = big.toByteArray();
int buflen = buf.length;
if (buf[0] == 0) {
buflen -= 1;
}
int len = Math.min((buflen + 3) / 4, Random.N);
int[] ints = bigEndianToInts(buf, len);
if (len <= 1) {
this.mt = new Random(ints[0]);
} else {
this.mt = new Random(ints);
}
} else {
throw vseed.getRuntime().newTypeError(
String.format("failed to convert %s into Integer", vseed.getMetaClass()
.getName()));