This content has been marked as final. Show 4 replies
Start by reading the documentation of java.util.Random. It also talks about SecureRandom, which, depending on your application, may be what you need.
Question: why the return is an array of longs, while the arguments min and max are ints?
Thanks for reply,
I'm using long array to more accurate values, if I want to read all java.util.Random so I don't need to put my question here!!
I want to tutorial or example or solution :(
I'm using long array to more accurate valuesThe range is specified in ints, and you are storing whole numbers, so this remark doesn't make any sense. Using a long for a value that fits into an int doesn't add precision, it just wastes space.
if I want to read all java.util.Random so I don't need to put my question here!!Exactly. So what's the problem?
I want to tutorial or example or solutionAnd you've been told where to find it.
981815 wrote:First off, there is no such thing as random numbers with equal probability--all random numbers in the computer world are called pseudo random numbers because they are all generated and follow a patter set forth by their algorithm. They will all have peeks and valleys in their distribution, but the best of them are near equal over extreamly long test cases. That does not mean that you couldn't ask for a random number and get a number, say 5, back 1000 times in a row; it's not very probable, but it could happen.
I wanna to generate numbers -in range- with equal probability*.
As stated in previos posts, the Random Class is what you are looking for, it you are not motivated enough to study it over, then you really do not need a solution that bad.
It appears that you are looking for whole numbers: you can guarentee that you do not get a repeat from your custom programmed random number method by hashing to the next open number in your range. You'll have to track each number as it is given from he Random object and hash to the next open if it has already been used.
In any case, we are glad to offer assistance in your leaning, but not provide ready made solutions for you.