Generate Random integer Numbers in Java

Description

The following code shows how to generate Random integer Numbers.

Example


// w  ww .  jav a 2  s.  c  o m
import java.util.Random;

public class Main {
  public static void main(String[] args) {
    Random diceValues = new Random();
    System.out.println(diceValues.nextInt(6));
    System.out.println(diceValues.nextInt(6));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization