Skip to content

Instantly share code, notes, and snippets.

@sachin-handiekar
Created January 25, 2013 12:13
Show Gist options
  • Save sachin-handiekar/4633978 to your computer and use it in GitHub Desktop.
Save sachin-handiekar/4633978 to your computer and use it in GitHub Desktop.
Generating a random long number between min and max.
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