Example usage for java.util Random Random

List of usage examples for java.util Random Random

Introduction

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

Prototype

public Random() 

Source Link

Document

Creates a new random number generator.

Usage

From source file:Main.java

public static long getRandomLong3() {
    Random rd = new Random();
    long l2 = 0;// ww  w .ja v  a 2 s.c  om
    l2 = (int) (Math.random() * 300);
    return l2;
}

From source file:Main.java

public static long nextPositiveLong() {
    Random random = new Random();
    return (long) (random.nextDouble() * Long.MAX_VALUE);
}

From source file:Main.java

public static String getRandColorCode() {
    String r, g, b;/*from w  w  w .  jav a 2  s.c  o  m*/
    Random random = new Random();
    r = Integer.toHexString(random.nextInt(256)).toUpperCase();
    g = Integer.toHexString(random.nextInt(256)).toUpperCase();
    b = Integer.toHexString(random.nextInt(256)).toUpperCase();
    r = r.length() == 1 ? "0" + r : r;
    g = g.length() == 1 ? "0" + g : g;
    b = b.length() == 1 ? "0" + b : b;
    return r + g + b;
}

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 String genNum() {
    int max = 200;
    int min = 100;
    Random random = new Random();
    int s = random.nextInt(max) % (max - min + 1) + min;
    return s + "";
}

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);
}

From source file:Main.java

public static void shuffle_array(int[] array) {
    int index, temp;
    Random random = new Random();
    for (int i = array.length - 1; i > 0; i--) {
        index = random.nextInt(i + 1);//from w  ww .j av  a  2s.c o  m
        temp = array[index];
        array[index] = array[i];
        array[i] = temp;
    }
}

From source file:Main.java

public static int randomIndex(int count) {
    Random random = new Random();
    return random.nextInt(count);
}

From source file:Main.java

public static long getRandomLong4() {
    Random rd = new Random();
    long l2 = 0;//from w ww  .  j a v a 2  s  . c  o m
    for (int i = 1; i < 100; i++) {
        long l1 = (int) (Math.random() * 9000 + 1000);
        l2 = rd.nextInt(9000) + 1000;
    }
    return l2;
}

From source file:Main.java

/**
 * Returns a random int between 0 and 999.
 *//*w  ww .jav a  2 s.  com*/
public static int getRandom() {
    return new Random().nextInt(999);
}