Skip to content

Instantly share code, notes, and snippets.

@alex-stewart-sporty
Last active May 30, 2025 09:38
Show Gist options
  • Save alex-stewart-sporty/d024cba4f2f0fde8f7d22211454c500e to your computer and use it in GitHub Desktop.
Save alex-stewart-sporty/d024cba4f2f0fde8f7d22211454c500e to your computer and use it in GitHub Desktop.
import java.util.Random;
public class Dice {
private Integer faces;
public Dice(int faces) {
this.faces = faces;
}
public void setFaces(int faces) {
this.faces = faces;
}
public Integer roll() {
Random var = new Random();
return var.nextInt(faces);
}
public Integer rollingSummingX(int x) {
int r = 0;
for (int i = 0; i < x; i++) {
r = r + roll();
}
return r;
}
public Integer[] rollingX(Integer x) {
Integer[] results = new Integer[x];
for (int i = 0; i < x; i++) {
results[i] = roll();
}
return results;
}
public String flipCoin() {
if (new Random().nextInt(2) == 0) {
return "heads";
} else {
return "tails";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment