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() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.

Usage

From source file:Main.java

public static void main(String[] argv) {

    Random r = new Random();
    int randint = Math.abs(r.nextInt()) % 11;
    System.out.println(randint);/*from  www  .  j  a v a 2 s . com*/
}

From source file:Main.java

public static void main(String args[]) {
    anArray = new double[10];
    Random rand = new Random();
    for (int i = 0; i < 10; i++) {
        anArray[i] = rand.nextInt();
    }//from w  ww.  java2  s. c  om
    System.out.println(Arrays.toString(anArray));
}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random();

    // get next next pseudorandom value 
    int value = randomno.nextInt();

    // check the value  
    System.out.println("Value is: " + value);
}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random();

    // check next int value  
    System.out.println("Next int value: " + randomno.nextInt());
}

From source file:MainClass.java

public static void main(String args[]) {

    Random generator = new Random();

    for (int i = 0; i < 10; i++)
        System.out.println(generator.nextInt());
}

From source file:Main.java

public static void main(String args[]) {
    int a = 0, b = 0, c = 0;
    Random r = new Random();
    for (int i = 0; i < 32000; i++) {
        try {/*from   w  ww .ja v  a2 s. c om*/
            b = r.nextInt();
            c = r.nextInt();
            a = 12345 / (b / c);
        } catch (ArithmeticException e) {
            System.out.println("Exception: " + e);
            a = 0; // set a to zero and continue
        }
        System.out.println("a: " + a);
    }
}

From source file:Main.java

public static void main(String args[]) {
    int a = 0, b = 0, c = 0;
    Random r = new Random();
    for (int i = 0; i < 32000; i++) {
        try {/* ww w  . j  a v  a2  s.  c  o m*/
            b = r.nextInt();
            c = r.nextInt();
            a = 12345 / (b / c);
        } catch (ArithmeticException e) {
            System.out.println("Division by zero.");
            a = 0; // set a to zero and continue
        }
        System.out.println("a: " + a);
    }
}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random(1234567890987655L);

    // get next next pseudorandom value 
    int value = randomno.nextInt();

    // check the value  
    System.out.println("Value is: " + value);
}

From source file:Main.java

public static void main(String[] args) {
    Random random = new Random();
    Set<Integer> set = new HashSet<Integer>();
    while (set.size() < 5) {
        set.add(random.nextInt());
    }//  ww w .ja  v a 2s.co  m
    List<Integer> result = new ArrayList<Integer>(set);
    System.out.println(result);
}

From source file:MainClass.java

public static void main(String args[]) {
    Object array = Array.newInstance(int.class, 3);

    int length = Array.getLength(array);
    Random generator = new Random(System.currentTimeMillis());
    for (int i = 0; i < length; i++) {
        int random = generator.nextInt();
        Array.setInt(array, i, random);
    }/*from   w w  w .  j a va2  s .  co  m*/

    for (int i = 0; i < length; i++) {
        int value = Array.getInt(array, i);
        System.out.println("Position: " + i + ", value: " + value);
    }
}