Created
January 25, 2013 12:13
-
-
Save sachin-handiekar/4633978 to your computer and use it in GitHub Desktop.
Generating a random long number between min and max.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class Main { | |
public static long generateRandom(long min, long max) { | |
double rValue = new Random().nextDouble(); | |
return (long) ((rValue * max) + ((1.0 - rValue) * min) + rValue); | |
} | |
public static void main(String[] args) { | |
System.out.println(generateRandom(1, Long.MAX_VALUE)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment