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

private static int getRandom() {
    int index = new Random().nextInt(5);
    return randoms[index];
}

From source file:Main.java

public static int[] generateUnsortedArray(int length, int maxValue) {
    int[] array = new int[length];
    Random r = new Random();
    for (int i = 0; i < length; i++) {
        array[i] = r.nextInt(maxValue) + 1; // Avoid 0 value for better drawing
    }//from ww w.  java2 s.c o  m
    return array;
}

From source file:Main.java

static String GenRandomNumber(int iLen) {
    String s = "";
    for (int i = 0; i < iLen; ++i) {
        int r = new Random().nextInt(10);
        s += String.valueOf(r);/*from w  w w. jav a2s .  co  m*/
    }

    return s;
}

From source file:Main.java

public static int getRandomColor() {
    Random rnd = new Random();
    return Color.argb(50, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
}

From source file:Main.java

public static void random(int[] input) {

    for (int i = 0; i < input.length - 1; i++) {
        int randomIndex = new Random().nextInt(input.length - 1);
        int temp = input[randomIndex];
        // swap numbers
        input[randomIndex] = input[input.length - 1 - i];
        input[input.length - 1 - i] = temp;
    }/*from   w  w w  .  jav  a  2 s . co  m*/
}

From source file:Main.java

public static String getSharePicName(File cacheFile, String[] urls) {
    return cacheFile.getAbsolutePath() + new Random().nextInt(100000) + "." + urls[urls.length - 1];
}

From source file:Main.java

public static String RandomString(int length) {
    String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Random rnd = new Random();

    StringBuilder sb = new StringBuilder(length);
    for (int i = 0; i < length; i++) {
        sb.append(AB.charAt(rnd.nextInt(AB.length())));
    }/*  w ww  .  ja  va2s .  c  o m*/
    return sb.toString();

}

From source file:Main.java

public static int getRandomColor() {
    Random random = new Random();
    int alpha = random.nextInt(50) + 206;
    int red = random.nextInt(200);
    int green = random.nextInt(200);
    int blue = random.nextInt(200);
    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

private static String randomABC(int n) {
    String chars = "abcde0123456789";
    String res = "";
    Random rnd = new Random();
    int leng = chars.length();
    for (int i = 0; i < n; i++) {
        res = res + chars.charAt(rnd.nextInt(leng));

    }/*from   w w  w.ja  v a  2 s. c o  m*/
    return res;
}

From source file:Main.java

public static String generateRandomString(int len) {
    String str = "0123456789abcdefghijklmnopqrstuvwxyz";
    Random rnd = new Random();
    StringBuilder sb = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
        sb.append(str.charAt(rnd.nextInt(str.length())));
    }//  ww w  .  j  a va  2  s  .co m
    return sb.toString();
}