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

public static Pair<Integer, Integer> randomBalanceAndAccountNumbers() {
    Random random = new Random();
    Integer balance = random.nextInt(80000);
    Integer account = 10000000 + random.nextInt(90000000);

    return Pair.create(balance, account);
}

From source file:Main.java

/**
 * Get a random number between a min and max
 * @param min lower end min/*from  w  w w.  j a v  a2 s.  c  om*/
 * @param max higher end max
 * @return
 */
public static int getRandomInt(int min, int max) {
    Random rand = new Random();
    int randomNum = rand.nextInt((max - min) + 1) + min;
    return randomNum;
}

From source file:Main.java

public static int generateBeautifulColor() {
    Random random = new Random();

    int red = 30 + random.nextInt(200);
    int green = 30 + random.nextInt(200);
    int blue = 30 + random.nextInt(200);
    return Color.rgb(red, green, blue);
}

From source file:Main.java

public static int generateRandom(int min, int max) {
    Random random = new Random();
    int randomInt = random.nextInt((max - min) + 1) + min;
    if (randomInt > max) {
        randomInt -= min;//  ww w.j av  a2 s. co m
    }
    return randomInt;
}

From source file:Main.java

public static <T> T random(List<T> list, Random random) {
    return list.get(random.nextInt(list.size()));
}

From source file:Main.java

public static int radrom(int max, int position) {
    Random random = new Random();
    int randomNum = random.nextInt(max);
    if (position == randomNum) {
        randomNum = radrom(max, position);
    }//w  w w.  ja v a 2s.  com
    return randomNum;
}

From source file:Gesture.java

public static void generateDraw(Gesture gesture) {
    final Random random = new Random();
    final int computerDraw = random.nextInt(3);
    System.out.println(computerDraw);

    if (computerDraw > gesture.getType()) {
        System.out.println("You lose.");
    } else if (computerDraw < gesture.getType()) {
        System.out.println("You win.");
    } else {//from   www.j a v  a 2 s  .co  m
        System.out.println("It is a tie.");

    }
}

From source file:Main.java

private static String getRandomHost() {
    Random r = new Random();
    return BEECLOUD_HOSTS[r.nextInt(BEECLOUD_HOSTS.length)] + HOST_API_VERSION;
}

From source file:Main.java

private static void BindPort() {
    Random random = new Random();
    port = random.nextInt(65535);

    try {//from  w w  w  . ja  v a2s  .  c o  m
        datagramSocket = new DatagramSocket(port);
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        BindPort();
    }
}

From source file:Main.java

public static int genrateBeautifulColor() {
    Random random = new Random();

    int red = 30 + random.nextInt(200);
    int green = 30 + random.nextInt(200);
    int blue = 30 + random.nextInt(200);

    return Color.rgb(red, green, blue);
}