-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomGen.java
More file actions
60 lines (50 loc) · 1.3 KB
/
RandomGen.java
File metadata and controls
60 lines (50 loc) · 1.3 KB
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
package Lab4;
/*
* Random Number Generator:
* This class generates various kinds of random numbers for
* the Computer's usage.
*/
public class RandomGen {
// Generator for the Computer's random choice (Rock, Paper, Scissors)
public int move()
{
int num = 0;
int loop = 1;
do {
num = (int)(Math.random()*9);
switch (num)
{case 1:
case 2:
case 3:
num = 1;
return num;
case 4:
case 5:
case 6:
num = 2;
return num;
case 7:
case 8:
case 9:
num = 3;
return num;
default:
break;}
} while (loop != 0);
return num;
}
// Generator for a random number
public int random()
{
int num = (int)(Math.random()*10);
return num;
}
// Generator for a coin toss
public int coin()
{
int coin;
int num = (int)(Math.random()*101);
coin = num%2;
return coin;
}
}