aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/pwgen/randnum.java
blob: 83cf4b038d3cf5e5639da37b5cdc08f5f13767c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
    }
}