GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||
GeezerVison is showing www.tutorialspoint.com — Java Random Class
Selected Reading
Java Random ClassIntroductionThe Java Random class instance is used to generate a stream of pseudorandom numbers.Following are the important points about Random −
Class declarationFollowing is the declaration for java.util.Random class − public class Random extends Object implements Serializable Class constructors
Class methods
Methods inheritedThis class inherits methods from the following classes −
Getting a Random Double Number ExampleThe following example shows the usage of Java Random doubles() method. Firstly, we've created a Random object and then using doubles() we retrieved a stream of random double values and printed first value. package com.tutorialspoint;
import java.util.Random;
import java.util.stream.DoubleStream;
public class RandomDemo {
public static void main( String args[] ) {
// create random object
DoubleStream randomNoStream = new Random().doubles();
// print a random double value
randomNoStream.limit(1).forEach( i -> System.out.println(i));
}
}
OutputLet us compile and run the above program, this will produce the following result. 0.5129590222446587 Advertisements
| ||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |