+ 2

# [Solved][CharGen]math.random() is not random enough

It seems that all the times i have it run, i am getting a lot of middle numbers. not very many highs or lows. for example, if i want a random number between 0-5 i get a lot of 2s and 3s some 4s and 1s but almost never any 0s or 5s. Update: still not seeing any range variation after using "java.util.concurrent.ThreadLocalRandom;" Solution: i needed to tweek the numbers it was randomly generating to extend the range and reduce the offset.

3 Answers

+ 5

I copied your "Character generator" program, stripped out everything that wasn't a random() call, then calculated the balance of each result over 100,000 iterations (for each category).
After compensating for the "stats retries" (for being too low) -- and just counting retries for 11 -- the output looks fairly balanced, so you might be seeing local effects.
I didn't test for any sort of grouping, but (like flipping tails 100x in a row) an infinite RNG could hang around a place for "as long as it wants", since I think it only has to even out after infinite time. Forcing apparent smoothness in a shorter time is non-random, but it's an interesting idea...
https://code.sololearn.com/cfcWVOC88168/?ref=app
(Percentage totals won't be exactly 100% due to rounding)

+ 4

I think localRandomThreads would be the 'most random'. Try testing and comparing Math.random to it.
This is the code:
import java.util.concurrent.ThreadLocalRandom;
int randomNum = ThreadLocalRandom.current().nextInt(0, 6);
This should produce a random number from 0-5.

0

Probably you have to modify the seed like C