@@ -7,32 +7,41 @@ namespace EncryptionTests
7
7
[ TestClass ]
8
8
internal static class TestUtilities
9
9
{
10
- public static string GeneratePassPhrase ( )
10
+ private static Random rand ;
11
+
12
+ private static Random Rand
11
13
{
12
- Random rand = new Random ( ) ;
14
+ get
15
+ {
16
+ if ( rand == null )
17
+ {
18
+ rand = new Random ( ) ;
19
+ }
13
20
14
- return GenerateRandomString ( rand . Next ( 8 , ( 256 + 1 ) ) ) ;
21
+ return rand ;
22
+ }
15
23
}
16
24
17
- public static byte [ ] GeneratePayload ( )
25
+ public static string GeneratePassPhrase ( )
18
26
{
19
- Random rand = new Random ( ) ;
27
+ return GenerateRandomString ( Rand . Next ( 8 , ( 256 + 1 ) ) ) ;
28
+ }
20
29
21
- return GenerateRandomBytes ( rand . Next ( 16 , ( 512 + 1 ) ) ) ;
30
+ public static byte [ ] GeneratePayload ( )
31
+ {
32
+ return GenerateRandomBytes ( Rand . Next ( 16 , ( 512 + 1 ) ) ) ;
22
33
}
23
34
24
35
private static string GenerateRandomString ( int length )
25
36
{
26
37
byte [ ] bytes = new byte [ length ] ;
27
38
28
- Random rand = new Random ( ) ;
29
-
30
39
for ( int i = 0 ; i < bytes . Length ; i ++ )
31
40
{
32
41
int min ;
33
42
int max ;
34
43
35
- if ( rand . Next ( 0 , 2 ) > 0 )
44
+ if ( Rand . Next ( 0 , 2 ) > 0 )
36
45
{
37
46
min = 65 ;
38
47
max = 90 ;
@@ -43,7 +52,7 @@ private static string GenerateRandomString(int length)
43
52
max = 122 ;
44
53
}
45
54
46
- int num = rand . Next ( min , max ) ;
55
+ int num = Rand . Next ( min , max ) ;
47
56
48
57
bytes [ i ] = ( byte ) num ;
49
58
}
@@ -53,11 +62,9 @@ private static string GenerateRandomString(int length)
53
62
54
63
private static byte [ ] GenerateRandomBytes ( int length )
55
64
{
56
- Random rand = new Random ( ) ;
57
-
58
65
byte [ ] bytes = new byte [ length ] ;
59
66
60
- rand . NextBytes ( bytes ) ;
67
+ Rand . NextBytes ( bytes ) ;
61
68
62
69
return bytes ;
63
70
}
0 commit comments