Created
January 11, 2016 00:10
-
-
Save WilliamHester/a286a5ce08f04c4abfd5 to your computer and use it in GitHub Desktop.
LotteryNumbers.java
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.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