forked from justinszaro/WarringNations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDice.java
More file actions
53 lines (47 loc) · 1.12 KB
/
Dice.java
File metadata and controls
53 lines (47 loc) · 1.12 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
import java.util.Random;
/**
* The Dice object generates a random numbers based on the number of faces or a long.
*
* @author Max Schuman, Elizabeth Vicente, Tanishq Iyer, Justin Szaro
* @version 3.0
* @since 2021-04-11
*/
public class Dice {
Random generator;
Random faceGenerator;
/**
* Creates a dice object.
* @param date the seed.
*/
public Dice(long date) {
generator = new Random(date);
faceGenerator = new Random();
}
/**
* Creates a dice.
*/
public Dice() {
generator = new Random();
faceGenerator = new Random();
}
/**
* Rolls a number between 0 and 1.
* @return a random number between 0 and 1.
*/
public float roll()
{
System.out.println("");
return generator.nextFloat();
}
/**
* Rolls a dice with int faces.
* @param faces the number of faces on the die.
* @return a number between 1-faces.
*/
public int rollFaces(int faces) {
int number = faceGenerator.nextInt(faces + 1);
if (number == 0)
return 1;
return number;
}
}