Example usage for java.util Random nextInt

List of usage examples for java.util Random nextInt

Introduction

In this page you can find the example usage for java.util Random nextInt.

Prototype

public int nextInt(int bound) 

Source Link

Document

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Usage

From source file:Main.java

/**
 * use and random value,maybe this can provide good experince
 *
 * @param min//  w  ww. jav  a2s. c  o  m
 * @param max
 * @return
 */
public static int getRandom(int min, int max) {
    Random random = new Random();
    return random.nextInt(Math.abs(max - min)) + min;
}

From source file:Main.java

public static int randInt() {
    Random rand = new Random();
    int randomNum = rand.nextInt((50000 - 0) + 1) + 0;
    return randomNum;
}

From source file:Main.java

public static char RandomCharFromStr(String str) {
    Random random = new Random();
    int index = random.nextInt(str.length());
    return str.charAt(index);
}

From source file:Main.java

public static char getRandomCharacter() {
    Random r = new Random();
    char c = (char) (r.nextInt(26) + 'a');

    return c;/*  ww  w  .ja va  2s .  c  o m*/
}

From source file:Main.java

public static int ParseColor() {
    Random random = new Random();
    int red = random.nextInt(255);
    int green = random.nextInt(255);
    int blue = random.nextInt(255);
    return Color.argb(255, red, green, blue);
}

From source file:Main.java

public static String RandomTenThousand() {
    Random random = new Random();
    int randNum = random.nextInt(9000) + 1000;
    return randNum + "";
}

From source file:Main.java

public static int randomColor() {
    Random __rdn = new Random();
    int __red = __rdn.nextInt(255);
    int __green = __rdn.nextInt(255);
    int __blue = __rdn.nextInt(255);
    return Color.rgb(__red, __green, __blue);
}

From source file:Main.java

public static boolean isFlee() {
    Random random = new Random();

    int num = random.nextInt(10);

    return num < 2;
}

From source file:Test.java

private static void startUpdateThread(int i, final ConcurrentMap<Integer, String> concurrentMap) {
    Thread thread = new Thread(new Runnable() {
        public void run() {
            while (!Thread.interrupted()) {
                Random random = new Random();
                int randomInt = random.nextInt(20);
                concurrentMap.put(randomInt, UUID.randomUUID().toString());
            }//from w  w w  .ja  va  2s. c om
        }
    });
    thread.setName("Update Thread " + i);
    updateThreads.add(thread);
    thread.start();
}

From source file:Main.java

public static int proLevelRandom(int i) {
    Random generator = new Random();
    int result = generator.nextInt(i);
    return result;
}