Package org.jruby.util

Examples of org.jruby.util.Random


        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()));
View Full Code Here


            byte[] bytes = state.getBigIntegerValue().toByteArray();
            int[] ints = new int[bytes.length / 4];
            for (int i = 0; i < ints.length; ++i) {
                ints[i] = getIntBigIntegerBuffer(bytes, i);
            }
            this.mt = new Random(ints, left);
        }
View Full Code Here

            return (629 + seed.hashCode()) * 37 + mt.hashCode();
        }

        RandomType(RandomType orig) {
            this.seed = orig.seed;
            this.mt = new Random(orig.mt);
        }
View Full Code Here

        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()));
View Full Code Here

            byte[] bytes = state.getBigIntegerValue().toByteArray();
            int[] ints = new int[bytes.length / 4];
            for (int i = 0; i < ints.length; ++i) {
                ints[i] = getIntBigIntegerBuffer(bytes, i);
            }
            this.mt = new Random(ints, left);
        }
View Full Code Here

            return (629 + seed.hashCode()) * 37 + mt.hashCode();
        }

        RandomType(RandomType orig) {
            this.seed = orig.seed;
            this.mt = new Random(orig.mt);
        }
View Full Code Here

TOP

Related Classes of org.jruby.util.Random

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.