From d2a252a06b589edee912e1193ab2804ff9238dd3 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Fri, 10 Jul 2015 19:44:22 -0400 Subject: Import pwgen classes --- .../java/com/zeapo/pwdstore/pwgen/randnum.java | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java (limited to 'app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java') diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java b/app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java new file mode 100644 index 00000000..83cf4b03 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java @@ -0,0 +1,26 @@ +package com.zeapo.pwdstore.pwgen; + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +public class randnum { + private static SecureRandom random; + + static { + try { + random = SecureRandom.getInstance("SHA1PRNG"); + } catch (NoSuchAlgorithmException e) { + throw new SecurityException("SHA1PRNG not available", e); + } + } + + /** + * Generate a random number n, where 0 <= n < maxNum. + * + * @param maxNum the bound on the random number to be returned + * @return the generated random number + */ + public static int number(int maxNum) { + return random.nextInt(maxNum); + } +} -- cgit v1.2.3