Answer the question
In order to leave comments, you need to log in
How does random work in java?
I have a list of numbers. The minimum number in the list is 97, the maximum is 955.
There are 42 numbers in total.
I use the method "mathRandd=(int)(Math.random() * 1000) + 1", the same numbers appear suspiciously often. Those. several basic numbers (2-3) drop out very often, and others are already "randomly" to them. Moreover, if the program initially "selected" several numbers, then until I replace the entire list, it is these numbers that will be the base ones all the time (that is, at each start, the selection of frequently falling numbers is saved).
The question is - is it harmful to program at night, or is there an explanation and is it better to use some other random?
Answer the question
In order to leave comments, you need to log in
Usually such observations deceive you, so it’s better not to trust yourself and your eyes,
build an output histogram, and then if it differs very much from a uniform distribution, draw conclusions, but I dare to assure Java Math.random() will not differ with a large number of runs .
Although of course Math.random is a bad random number generator, but not as good as you describe.
I would advise you to still use commons.apache.org/proper/commons-math/apidocs/org...
Math.random() is sometimes difficult to describe complex cases of randomization.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question