-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRand7.java
More file actions
26 lines (21 loc) · 829 Bytes
/
Copy pathRand7.java
File metadata and controls
26 lines (21 loc) · 829 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
25
26
package DailyCoding;
import java.util.Random;
public class Rand7
{/*this class defines computes a and return a random number from 1 to 7 with the use of a rand5() method
*/
public static void main(String[] args)
{
//test
Rand7 Ra = new Rand7();
System.out.println(Ra.Rand());
}
Random rand = new Random();
private int Rand5(){ return rand.nextInt(6);} //This methode returns random number in from 1 - 5 (inclusive)
public int Rand()
{/*Return random number from 1 - 7*/
//we have two choices; a random number from 1-5 and 6-7;
int[] A = new int[]{Rand5(),6,7}; ///list of possible numbers
int randomChoice = rand.nextInt(3); //Get random number from o - 2 for the options in list
return A[randomChoice];
}
}