forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.java
More file actions
24 lines (22 loc) · 821 Bytes
/
Copy pathRandom.java
File metadata and controls
24 lines (22 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Arrays;
public class Random{
public static void main(String[] args){
// testing Math.random()
System.out.println(Math.random());
System.out.println(Math.random());
System.out.println(Math.random());
// testing using Math.random to generate random numbers between 1 and 5
System.out.println((int)(Math.random()* 5));
System.out.println((int)(Math.random()* 5));
System.out.println((int)(Math.random()* 5));
// testing secret code generation (5 digits, each digit between 0 and 5)
System.out.println(Arrays.toString(createSecretCode(5, 6)));
}
public static int[] createSecretCode(int length, int numColors) {
int[] code = new int[length];
for (int i = 0; i < length; i++) {
code[i] = (int)(Math.random()*numColors) + 1;
}
return code;
}
}