diff --git a/src/main/java/com/github/strangercoug/freecasino/FreeCasino.java b/src/main/java/com/github/strangercoug/freecasino/FreeCasino.java index 79f074d..6d8d508 100644 --- a/src/main/java/com/github/strangercoug/freecasino/FreeCasino.java +++ b/src/main/java/com/github/strangercoug/freecasino/FreeCasino.java @@ -38,14 +38,23 @@ import com.github.strangercoug.freecasino.games.model.table.Craps; import com.github.strangercoug.freecasino.games.model.table.RedDog; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Scanner; +import java.util.random.RandomGenerator; /** * * @author Jeffrey Hope */ -class FreeCasino { +public class FreeCasino { + /** + * Backup RNG for offline use. Using the random.org API should be preferred + * to calling this RNG, especially if it is necessary to shuffle a large + * number of cards. + */ + public static final RandomGenerator rng = new SecureRandom(); + public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean validInput = false; diff --git a/src/main/java/com/github/strangercoug/freecasino/objs/Deck.java b/src/main/java/com/github/strangercoug/freecasino/objs/Deck.java index 44e16bd..27859b9 100644 --- a/src/main/java/com/github/strangercoug/freecasino/objs/Deck.java +++ b/src/main/java/com/github/strangercoug/freecasino/objs/Deck.java @@ -36,6 +36,8 @@ import java.security.SecureRandom; import java.util.LinkedList; +import static com.github.strangercoug.freecasino.FreeCasino.rng; + /** * * @author Jeffrey Hope @@ -45,7 +47,6 @@ public class Deck { private final int numDecks; private final boolean usesBlackJoker; private final boolean usesRedJoker; - private final SecureRandom rng = new SecureRandom(); public Deck(int numDecks, boolean usesBlackJoker, boolean usesRedJoker) { cards = new LinkedList<>(); @@ -82,16 +83,16 @@ public void populateDeck() { } } - /* TODO: This is fine for alpha and beta testing, but at a later point I - * would like to be able to detect whether there is an Internet connection and - * use the random.org API to shuffle if possible. If something goes wrong, we - * fall back to this. - */ public void shuffleDeck() { + /* TODO: This is fine for alpha and beta testing, but at a later point I would + * like to be able to detect whether there is an Internet connection and use + * the random.org API to shuffle if possible. If something goes wrong, we fall + * back to this. + */ for (int i = cards.size() - 1; i > 0; i--) { Card temp = cards.get(i); - int j = rng.nextInt(i + 1); /* Without the +1 this becomes a Sattolo shuffle, - * which we don't want */ + int j = rng.nextInt(i + 1); /* Without the +1 this becomes a Sattolo + * shuffle, which we don't want */ cards.set(i, cards.get(j)); cards.set(j, temp); } diff --git a/src/main/java/com/github/strangercoug/freecasino/objs/Dice.java b/src/main/java/com/github/strangercoug/freecasino/objs/Dice.java index b2e5d7b..9e85825 100644 --- a/src/main/java/com/github/strangercoug/freecasino/objs/Dice.java +++ b/src/main/java/com/github/strangercoug/freecasino/objs/Dice.java @@ -32,6 +32,8 @@ import java.security.SecureRandom; +import static com.github.strangercoug.freecasino.FreeCasino.rng; + /** * * @author Jeffrey Hope @@ -39,7 +41,6 @@ public class Dice { private final int[] dieFaces; private final int sidesPerDie; - private final SecureRandom rng = new SecureRandom(); /** * Creates a number of dice. @@ -112,7 +113,13 @@ public int getTotal() { * Rolls the dice. */ public void rollDice() { - for (int i = 0; i < dieFaces.length; i++) - dieFaces[i] = (rng.nextInt(sidesPerDie) + 1); + /* TODO: This is fine for alpha and beta testing, but at a later point I would + * like to be able to detect whether there is an Internet connection and use + * the random.org API to roll if possible. If something goes wrong, we fall + * back to this. + */ + for (int i = 0; i < dieFaces.length; i++) { + dieFaces[i] = (rng.nextInt(1, sidesPerDie + 1)); + } } } diff --git a/src/main/java/com/github/strangercoug/freecasino/objs/Wheel.java b/src/main/java/com/github/strangercoug/freecasino/objs/Wheel.java index 3e4c3e3..9c13404 100644 --- a/src/main/java/com/github/strangercoug/freecasino/objs/Wheel.java +++ b/src/main/java/com/github/strangercoug/freecasino/objs/Wheel.java @@ -30,7 +30,7 @@ */ package com.github.strangercoug.freecasino.objs; -import java.security.SecureRandom; +import static com.github.strangercoug.freecasino.FreeCasino.rng; /** * @@ -39,7 +39,6 @@ public class Wheel { private final Object[] stops; private int position; - private final SecureRandom rng = new SecureRandom(); public Wheel(Object[] stops) { this.stops = stops; @@ -51,6 +50,11 @@ public Object getWheelResult() { } public void spinWheel() { + /* TODO: This is fine for alpha and beta testing, but at a later point I would + * like to be able to detect whether there is an Internet connection and use + * the random.org API to roll if possible. If something goes wrong, we fall + * back to this. + */ position = rng.nextInt(stops.length); } }