Skip to content

Instantly share code, notes, and snippets.

@hakusaro
Created September 2, 2013 18:58
Show Gist options
  • Save hakusaro/6416141 to your computer and use it in GitHub Desktop.
Save hakusaro/6416141 to your computer and use it in GitHub Desktop.
public int generateValidPinCode(String seed) {
int pin = 0;
Random r = new Random(System.nanoTime() + seed.hashCode());
int randombit = r.nextInt(9) * 1000 + r.nextInt(999);
ResultSet results = sqlDatabase.executeQuery("SELECT * FROM warnings WHERE pin=?", randombit);
try {
if (results.next()) {
pin = generateValidPinCode(Integer.toString(randombit));
} else {
pin = randombit;
}
} catch (SQLException e) {
pin = randombit;
}
return pin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment