-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_seed.java
68 lines (46 loc) · 1.53 KB
/
generate_seed.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.security.*;
class generate_seed {
public static void main(String[] args) {
long nanoT1;
long nanoT2;
float deltaT;
float deltaT_ns;
float num_bits;
float throughput;
int i;
// number of random bytes to get for each call to generateSeed
int num_bytes = 24; // default = 24 bytes
// number of times to get 'num_bytes' bytes
int num_loops = 1; // default = 1 time
SecureRandom random = new SecureRandom();
// set algorithm to be used from command line: NativePRNG or SHA1PRNG
try {
random = SecureRandom.getInstance(args[0]);
} catch (NoSuchAlgorithmException ex) {
System.out.println("Unabe to switch requested algorithm.");
return;
}
// read num_bytes from command line
try {
num_bytes = Integer.parseInt(args[1]);
} catch (ArrayIndexOutOfBoundsException e) {
}
// read num_loops from command line
try {
num_loops = Integer.parseInt(args[2]);
} catch (ArrayIndexOutOfBoundsException e) {
}
byte[] b = new byte[num_bytes];
nanoT1 = System.nanoTime();
for (i = 0; i < num_loops; i++)
b = random.generateSeed(num_bytes);
nanoT2 = System.nanoTime();
deltaT_ns = nanoT2 - nanoT1; // ns
deltaT = deltaT_ns / 1_000_000_000; // s
num_bits = num_bytes*num_loops*8;
throughput = num_bits / deltaT; // b/s
throughput = throughput / 1_000_000; // Mbps
System.out.println(deltaT_ns + " ns");
System.out.printf("%f Mbps\n", throughput);
}
}