File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // A Java program to demonstrate random number generation
2+ // using java.util.Random;
3+ import java .util .Random ;
4+
5+ public class generateRandom {
6+
7+ public static void main (String args [])
8+ {
9+ // create instance of Random class
10+ Random rand = new Random ();
11+
12+ // Generate random integers in range 0 to 999
13+ int rand_int1 = rand .nextInt (1000 );
14+ int rand_int2 = rand .nextInt (1000 );
15+
16+ // Print random integers
17+ System .out .println ("Random Integers: " +rand_int1 );
18+ System .out .println ("Random Integers: " +rand_int2 );
19+
20+ // Generate Random doubles
21+ double rand_dub1 = rand .nextDouble ();
22+ double rand_dub2 = rand .nextDouble ();
23+
24+ // Print random doubles
25+ System .out .println ("Random Doubles: " +rand_dub1 );
26+ System .out .println ("Random Doubles: " +rand_dub2 );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments