-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomNumbers.java
76 lines (65 loc) · 2.49 KB
/
RandomNumbers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
public class RandomNumbers {
public static void main( String[] args ) {
int a, b, c, d;
double r, rps;
rps = Math.random();
if (rps < 0.3333333 ) { // will be true 1/3 of the time
System.out.println( "ROCK" );
}
else if ( rps < 0.6666667) {
System.out.println( "PAPER" );
}
else {
System.out.println( "SCISSORS" );
}
// pick four random integers, each 1-10
a = 1 + (int)( 10*Math.random() );
b = 1 + (int)( 10*Math.random() );
c = 1 + (int)( 10*Math.random() );
d = 1 + (int)( 10*Math.random() );
System.out.println( "1-10:\t" + a + "\t" + b + "\t" + c + "\t" + d );
// pick four random integers, each 1-6
a = 1 + (int)( 6*Math.random() );
b = 1 + (int)( 6*Math.random() );
c = 1 + (int)( 6*Math.random() );
d = 1 + (int)( 6*Math.random() );
System.out.println( "1-6:\t" + a + "\t" + a + "\t" + a + "\t" + a );
// pick a single random integer, 1-100
a = 1 + (int)( 100*Math.random() );
System.out.println( "1-100:\t" + a + "\t" + a + "\t" + a + "\t" + a );
// pick four random integers, each 1-100
a = 1 + (int)( 100*Math.random() );
b = 1 + (int)( 100*Math.random() );
c = 1 + (int)( 100*Math.random() );
d = 1 + (int)( 100*Math.random() );
System.out.println( "1-100:\t" + a + "\t" + b + "\t" + c + "\t" + d );
// pick four random integers, each 0-99
a = 0 + (int)( 100*Math.random() );
b = 0 + (int)( 100*Math.random() );
c = (int)(100*Math.random() );
d = (int)(100*Math.random() );
System.out.println( "0-99:\t" + a + "\t" + b + "\t" + c + "\t" + d );
// pick four random integers, each 10-20
a = 10 + (int)( 11*Math.random() );
b = 10 + (int)( 11*Math.random() );
c = 10 + (int)( 11*Math.random() );
d = 10 + (int)( 11*Math.random() );
System.out.println( "10-20:\t" + a + "\t" + b + "\t" + c + "\t" + d);
// display four random doubles each [0-1)
System.out.println( "0-1:\t" + Math.random() + "\t" + Math.random() );
r = 10 * Math.random();
System.out.println( "0-9.99:\t" + r );
System.out.println( "0-9:\t" + (int)r );
System.out.println( "1-10:\t" + (1 + (int)r) );
// pick a three random integers, each 1-3
a = 1 + (int)( 3*Math.random() );
b = 1 + (int)( 3*Math.random() );
c = 1 + (int)( 3*Math.random() );
System.out.println( "1-3:\t" + a + "\t" + b + "\t" + c);
// pick three random integers, each 5-10
a = 5 + (int)( 5*Math.random() );
b = 5 + (int)( 5*Math.random() );
c = 5 + (int)( 5*Math.random() );
System.out.println( "5-10:\t" + a + "\t" + b + "\t" + c);
}
}