Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.Random;
  2. /**
  3. * Provide control over the randomization of the simulation.
  4. *
  5. * @author Yemima Sutanto
  6. * @version 1.0 (22 November 2018)
  7. */
  8. public class Randomizer
  9. {
  10. // The default seed for control of randomization.
  11. private static final int SEED = 1111;
  12. // A shared Random object, if required.
  13. private static final Random rand = new Random(SEED);
  14. // Determine whether a shared random generator is to be provided.
  15. private static final boolean useShared = true;
  16. /**
  17. * Constructor for objects of class Randomizer
  18. */
  19. public Randomizer()
  20. {
  21. }
  22. /**
  23. * Provide a random generator.
  24. * @return A random object.
  25. */
  26. public static Random getRandom()
  27. {
  28. if(useShared) {
  29. return rand;
  30. }
  31. else {
  32. return new Random();
  33. }
  34. }
  35. /**
  36. * Reset the randomization.
  37. * This will have no effect if randomization is not through
  38. * a shared Random generator.
  39. */
  40. public static void reset()
  41. {
  42. if(useShared) {
  43. rand.setSeed(SEED);
  44. }
  45. }
  46. }