From 1b968a49403f68e09552179dff8908482a01ceaf Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Mon, 7 Dec 2020 08:50:48 +0100 Subject: [PATCH] j a v a d o c f o r g o o d r a n d o m --- RetardedClasses.iml | 11 ----------- src/main/java/GoodRandom.java | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/RetardedClasses.iml b/RetardedClasses.iml index 24d3784..28921e1 100644 --- a/RetardedClasses.iml +++ b/RetardedClasses.iml @@ -5,21 +5,10 @@ - - - - - - - - - - - diff --git a/src/main/java/GoodRandom.java b/src/main/java/GoodRandom.java index d58d054..e9a6441 100644 --- a/src/main/java/GoodRandom.java +++ b/src/main/java/GoodRandom.java @@ -16,18 +16,36 @@ public class GoodRandom { OpenTDB trivia = new OpenTDB(); + /** + * Create a new {@code GoodRandom} with a seed + * @param seed The seed + */ public GoodRandom(int seed) { trivia.setCategory(seed % 20 + 10); } + /** + * Create a new {@code GoodRandom} + */ public GoodRandom() { this(0); } + /** + * Get a random integer from 0 to {@code max}. Integers are not distributed equally if {@code max} is not a power of 2. + * @param max The maximum number + * @return A random Integer from 0 to {@code max} + */ public int randomInt(int max){ return randomInt(0, max); } + /** + * Get a random integer from {@code min} to {@code max}. Integers are not distributed equally if {@code max} - {@code min} is not a power of 2. + * @param min The minimum number + * @param max The maximum number + * @return A random Integer from 0 to {@code max} + */ public int randomInt(int min, int max){ int range = max - min; //exponent of next biggest power of two @@ -41,6 +59,11 @@ public class GoodRandom { return resultNormalized + min; } + /** + * Get a random number from 0 to 3 using OpenTDB. It pulls a random trivia question, + * sorts the answers alphabetically and returns the position of the correct answer + * @return A random number from 0 to 3 + */ private int getFourDigit(){ trivia.getTrivia(); ArrayList answers = new ArrayList<>();