This content has been marked as final. Show 4 replies
Probably because the original implementors didn't see the need.
You can specify bounds for the int then multiply/divide to whatever you need for your long.
creman42 wrote:Because due to the nature of floating point numbers you can easily calulate a random number in any given range from the random number in the range 0.0 to 1.0.
i need to generate a random number. I know i can use the class Random to do this, but i was wondering...
within this class, i can generate a random int, long, float etc. I can specify the bounds for a random int, but i cannot specify the bounds for a random long... which is what i need. why is this?
With integers you can't do that, because there are only 2 possible numbers in that range (assuming the range is inclusive).
This came up in another thread (just not in this form). Try:
new BigInteger(128, yourRandomObject).mod(new BigInteger(String.valueOf(yourLongValue))).longValue();