Java ThreadLocalRandom randomNum(int min, int max)

Here you can find the source of randomNum(int min, int max)

Description

random Num

License

Open Source License

Declaration

public static int randomNum(int min, int max) 

Method Source Code

//package com.java2s;

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    public static int randomNum(int min, int max) {
        if (min < 0) {
            int i = nextInt(max + 1 + Math.abs(min));
            return min + i;
        } else {/*w ww  . j  av  a2 s .c om*/
            int i = nextInt(max + 1 - min);
            return min + i;
        }
    }

    public static int nextInt(int val) {

        return nextInt(val, true);
    }

    public static int nextInt(int val, boolean isAbs) {
        int r = (int) (ThreadLocalRandom.current().nextDouble() * val);
        if (isAbs) {
            return Math.abs(r);
        }
        return r;
    }
}

Related

  1. randomInt(int bound)
  2. randomInteger(int min, int max)
  3. randomIntegerList(int min, int max, int minLength, int maxLength)
  4. randomLongs(final long count, final long min, final long max)
  5. randomLongsNonDuplicates(final long count, final long min, final long max)
  6. randomNums(int min, int max, int count)
  7. randomPer(long num, long divisor)
  8. randomReal(float range)
  9. randomSeed()