Java: random long number in 0 <= x < n range.

Posted by Vilius Normantas on Stack Overflow See other posts from Stack Overflow or by Vilius Normantas
Published on 2010-03-30T14:41:21Z Indexed on 2010/03/30 14:53 UTC
Read the original article Hit count: 433

Filed under:
|
|
|

Random class has a method to generate random int in a given range. For example:

Random r = new Random(); 
int x = r.nextInt(100);

This would generate an int number more or equal to 0 and less than 100. I'd like to do exactly the same with long number.

long y = magicRandomLongGenerator(100);

Random class has only nextLong(), but it doesn't allow to set range.

© Stack Overflow or respective owner

Related posts about java

Related posts about random