-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomSeed.java
35 lines (27 loc) · 1007 Bytes
/
RandomSeed.java
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
27
28
29
30
31
32
33
34
35
import java.io.PrintStream;
import java.security.SecureRandom;
import java.util.Random;
public class RandomSeed {
// This class provides you with a random number seed that you can use
// as a source of randomness in your programs. Use it like this:
//
// byte[] seed = RandomSeed.getArray();
//
// Afterward, seed will point to an array of RandomSeed.NumBytes
// bytes, which you can assume are random.
//
// If you call getArray more than once, it will return the
// same array (unchanged) every time, so don't try to use this as
// a random number generator by calling it repeatedly. Instead, use it
// as the initial seed of a generator that you create.
public static final int NumBytes = 16;
private static byte[] randBytes = null;
public static byte[] getArray() {
if(randBytes == null){
Random rand = new SecureRandom();
randBytes = new byte[NumBytes];
rand.nextBytes(randBytes);
}
return randBytes;
}
}