Java Random Int random(int n)

Here you can find the source of random(int n)

Description

random

License

Open Source License

Declaration

public static final int random(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static long state = 1;

    public static final int random(int n) {
        if (n == 1) {
            return 0;
        }/*  w w  w.  j a v  a2 s.c  om*/
        long r = ((nextLong() >>> 32) * n) >> 32;
        return (int) r;
    }

    public static final long nextLong() {
        long a = state;
        state = xorShift64(a);
        return a;
    }

    public static final long xorShift64(long a) {
        a ^= (a << 21);
        a ^= (a >>> 35);
        a ^= (a << 4);
        return a;
    }
}

Related

  1. random(int min, int max)
  2. random(int min, int max)
  3. random(int min, int max)
  4. random(int min, int max)
  5. random(int n)
  6. random(int numSamples)
  7. random(int range)
  8. random(int start, int end)
  9. random(int theRange)