Get Random numbers between 0.0 and 1.0 in Java

Description

The following code shows how to get Random numbers between 0.0 and 1.0.

Example


/*from  w w  w. ja  v a2  s. c om*/
public class Main {

  public static void main(String[] args) {
    
    for (int i = 0; i < 5; i++){
      System.out.println("Random Number [" + (i + 1) + "] : " + Math.random());
    }
  }

}

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