Skip to content

Commit b8ec4ec

Browse files
authored
Merge pull request mayankgb2#14 from mrinalmohan/master
Create random.java
2 parents eb18a45 + 0cb7b7b commit b8ec4ec

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

random.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)