New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RandGen for project-centric RNG functionality #59
Conversation
Codecov Report
@@ Coverage Diff @@
## development #59 +/- ##
=========================================
Coverage 0% 0%
=========================================
Files 17 18 +1
Lines 123 145 +22
Branches 2 4 +2
=========================================
- Misses 123 145 +22
Continue to review full report at Codecov.
|
efe54c2
to
96065d5
Compare
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi. I added a couple of questions in the file below. Please answer. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to give branches tags from now on. Like feature/random_generator, bugfix/generator_strings.
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/util/RandomGenerator.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, just some questions...
In the constructor, wouldn't it be better as super.setSeed instead of this.setSeed?
Also, we're going the Java route and doing include start and exclude end? This is something that might be good for us to keep a track of. If too many people keep doing a random with include end there'll be a lot of code with getIntInRange(start, end + 1).
Not something for you to change, though. Just something to keep in mind. I'm also not requesting changes because I'm not entirely sure of what I said before with super.setSeed.
Because you're not supposed to give negative ranges to the range method, it should indicate an issue if it's passed those. It now does. Additionally, the single-int overload of the method is now nicer.
Clean up javadocs
Setting a seedString to the result of parsing it as a Long, as it was before this commit, runs it through a format process which can modify it in unexpected ways, like dropping leading zeroes. This doesn't align with the goal of preserving the original seedString input.
src/main/java/com/worldwarofants/game/module/utils/RandomGenerator.java
Outdated
Show resolved
Hide resolved
src/main/java/com/worldwarofants/game/module/utils/RandomGenerator.java
Outdated
Show resolved
Hide resolved
if (start > end) { | ||
return end; | ||
} | ||
int randomNumber = this.nextInt(end - start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a chance this could overflow, namely when (end - start) > Integer.MAX_VALUE. There's not a nice fix for this using the Random class as nextLong() doesn't have a bounded method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think separating the tests to another package might be best. Not sure what exactly should the structure be though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of my suggestions have now been handled.
@Plat251 Good to merge? Looks like so on my end? |
@RedRoyalDog |
This should allow the developers to rely on a single common implementation of random number generation, with features like seed recording as well as strings as seeds.