Skip to content

Instantly share code, notes, and snippets.

@WilliamHester
Created January 11, 2016 00:10
Show Gist options
  • Save WilliamHester/a286a5ce08f04c4abfd5 to your computer and use it in GitHub Desktop.
Save WilliamHester/a286a5ce08f04c4abfd5 to your computer and use it in GitHub Desktop.
LotteryNumbers.java
import java.math.*;
import java.util.*;
import java.security.*;
public class LotteryNumbers {
public static void main(String[] args) {
SecureRandom random = new SecureRandom();
byte[] bytes = new byte[1];
TreeSet<Integer> ints = new TreeSet<>();
while (ints.size() < 5) {
random.nextBytes(bytes);
int val = new BigInteger(bytes).intValue() + 128;
double ratio = ((double) val) / 256;
ints.add((int) Math.round(ratio * 69) + 1);
}
int val = new BigInteger(bytes).intValue() + 128;
double ratio = ((double) val) / 256;
for (int i : ints) {
System.out.print(i + " ");
}
System.out.println(Math.round(ratio * 26 + 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment