j a v a d o c f o r g o o d r a n d o m

This commit is contained in:
nora 2020-12-07 08:50:48 +01:00
parent 095fb3ee15
commit 1b968a4940
2 changed files with 23 additions and 11 deletions

View file

@ -5,21 +5,10 @@
<output-test url="file://$MODULE_DIR$/target/test-classes" /> <output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/19.0.0/annotations-19.0.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: com.github.shinixsensei-dev:OpenTDB4j:1.1.0" level="project" /> <orderEntry type="library" name="Maven: com.github.shinixsensei-dev:OpenTDB4j:1.1.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20200518" level="project" /> <orderEntry type="library" name="Maven: org.json:json:20200518" level="project" />
</component> </component>

View file

@ -16,18 +16,36 @@ public class GoodRandom {
OpenTDB trivia = new OpenTDB(); OpenTDB trivia = new OpenTDB();
/**
* Create a new {@code GoodRandom} with a seed
* @param seed The seed
*/
public GoodRandom(int seed) { public GoodRandom(int seed) {
trivia.setCategory(seed % 20 + 10); trivia.setCategory(seed % 20 + 10);
} }
/**
* Create a new {@code GoodRandom}
*/
public GoodRandom() { public GoodRandom() {
this(0); 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){ public int randomInt(int max){
return randomInt(0, 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){ public int randomInt(int min, int max){
int range = max - min; int range = max - min;
//exponent of next biggest power of two //exponent of next biggest power of two
@ -41,6 +59,11 @@ public class GoodRandom {
return resultNormalized + min; 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(){ private int getFourDigit(){
trivia.getTrivia(); trivia.getTrivia();
ArrayList<String> answers = new ArrayList<>(); ArrayList<String> answers = new ArrayList<>();