| @@ -39,19 +39,19 @@ namespace GSF.Security.Cryptography · 38 unmodified lines |
| 39 | /// </summary> | 39 | /// </summary> |
| 40 | public static class Random | 40 | public static class Random |
| 41 | { | 41 | { |
| 42 | private static readonly RNGCryptoServiceProvider s_randomNumberGenerator = new RNGCryptoServiceProvider(); | 42 | private static readonly RNGCryptoServiceProvider RandomNumberGenerator = new RNGCryptoServiceProvider(); |
| 43 | | 43 | |
| 44 | /// <summary> | 44 | /// <summary> |
| 45 | /// Generates a cryptographically strong double-precision floating-point random number between zero and one. | 45 | /// Generates a cryptographically strong double-precision floating-point random number between zero and one. |
| 46 | /// </summary> | 46 | /// </summary> |
| 47 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 47 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 48 | public static double Number | 48 | public static double Number |
| 49 | { | 49 | { |
| 50 | get | 50 | get |
| 51 | { | 51 | { |
| 52 | unchecked | 52 | unchecked |
| 53 | { | 53 | { |
| 54 | return (double)UInt32 / (double)uint.MaxValue; | 54 | return UInt32 / (uint.MaxValue + 1.0D); |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| @@ -59,14 +59,14 @@ namespace GSF.Security.Cryptography · 1 unmodified line |
| 59 | /// <summary> | 59 | /// <summary> |
| 60 | /// Generates a cryptographically strong random decimal between zero and one. | 60 | /// Generates a cryptographically strong random decimal between zero and one. |
| 61 | /// </summary> | 61 | /// </summary> |
| 62 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 62 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 63 | public static decimal Decimal | 63 | public static decimal Decimal |
| 64 | { | 64 | { |
| 65 | get | 65 | get |
| 66 | { | 66 | { |
| 67 | unchecked | 67 | unchecked |
| 68 | { | 68 | { |
| 69 | return (decimal)UInt64 / (decimal)ulong.MaxValue; | 69 | return UInt64 / (ulong.MaxValue + 1.0M); |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| @@ -76,7 +76,7 @@ namespace GSF.Security.Cryptography · 3 unmodified lines |
| 76 | /// </summary> | 76 | /// </summary> |
| 77 | /// <param name="startNumber">A <see cref="double"/> that is the low end of our range.</param> | 77 | /// <param name="startNumber">A <see cref="double"/> that is the low end of our range.</param> |
| 78 | /// <param name="stopNumber">A <see cref="double"/> that is the high end of our range.</param> | 78 | /// <param name="stopNumber">A <see cref="double"/> that is the high end of our range.</param> |
| 79 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 79 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 80 | /// <returns>A <see cref="double"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>, or an excception.</returns> | 80 | /// <returns>A <see cref="double"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>, or an excception.</returns> |
| 81 | public static double Between(double startNumber, double stopNumber) | 81 | public static double Between(double startNumber, double stopNumber) |
| 82 | { | 82 | { |
| @@ -94,24 +94,24 @@ namespace GSF.Security.Cryptography · 11 unmodified lines |
| 94 | /// <para>The length of the byte array determines how many cryptographically strong random bytes are produced.</para> | 94 | /// <para>The length of the byte array determines how many cryptographically strong random bytes are produced.</para> |
| 95 | /// <para>This method is thread safe.</para> | 95 | /// <para>This method is thread safe.</para> |
| 96 | /// </remarks> | 96 | /// </remarks> |
| 97 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 97 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 98 | /// <exception cref="System.ArgumentNullException">buffer is null.</exception> | 98 | /// <exception cref="ArgumentNullException">buffer is null.</exception> |
| 99 | public static void GetBytes(byte[] buffer) | 99 | public static void GetBytes(byte[] buffer) |
| 100 | { | 100 | { |
| 101 | s_randomNumberGenerator.GetBytes(buffer); | 101 | RandomNumberGenerator.GetBytes(buffer); |
| 102 | } | 102 | } |
| 103 | | 103 | |
| 104 | /// <summary> | 104 | /// <summary> |
| 105 | /// Generates a cryptographically strong random boolean (i.e., a coin toss). | 105 | /// Generates a cryptographically strong random boolean (i.e., a coin toss). |
| 106 | /// </summary> | 106 | /// </summary> |
| 107 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 107 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 108 | public static bool Boolean | 108 | public static bool Boolean |
| 109 | { | 109 | { |
| 110 | get | 110 | get |
| 111 | { | 111 | { |
| 112 | byte[] value = new byte[1]; | 112 | byte[] value = new byte[1]; |
| 113 | | 113 | |
| 114 | s_randomNumberGenerator.GetBytes(value); | 114 | RandomNumberGenerator.GetBytes(value); |
| 115 | | 115 | |
| 116 | return value[0] % 2 == 0; | 116 | return value[0] % 2 == 0; |
| 117 | } | 117 | } |
| @@ -120,14 +120,14 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 120 | /// <summary> | 120 | /// <summary> |
| 121 | /// Generates a cryptographically strong 8-bit random integer. | 121 | /// Generates a cryptographically strong 8-bit random integer. |
| 122 | /// </summary> | 122 | /// </summary> |
| 123 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 123 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 124 | public static byte Byte | 124 | public static byte Byte |
| 125 | { | 125 | { |
| 126 | get | 126 | get |
| 127 | { | 127 | { |
| 128 | byte[] value = new byte[1]; | 128 | byte[] value = new byte[1]; |
| 129 | | 129 | |
| 130 | s_randomNumberGenerator.GetBytes(value); | 130 | RandomNumberGenerator.GetBytes(value); |
| 131 | | 131 | |
| 132 | return value[0]; | 132 | return value[0]; |
| 133 | } | 133 | } |
| @@ -136,7 +136,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 136 | /// <summary> | 136 | /// <summary> |
| 137 | /// Generates a cryptographically strong 8-bit random integer between specified values. | 137 | /// Generates a cryptographically strong 8-bit random integer between specified values. |
| 138 | /// </summary> | 138 | /// </summary> |
| 139 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 139 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 140 | /// <param name="startNumber">A <see cref="byte"/> that is the low end of our range.</param> | 140 | /// <param name="startNumber">A <see cref="byte"/> that is the low end of our range.</param> |
| 141 | /// <param name="stopNumber">A <see cref="byte"/> that is the high end of our range.</param> | 141 | /// <param name="stopNumber">A <see cref="byte"/> that is the high end of our range.</param> |
| 142 | /// <returns>A <see cref="byte"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 142 | /// <returns>A <see cref="byte"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -151,14 +151,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 151 | /// <summary> | 151 | /// <summary> |
| 152 | /// Generates a cryptographically strong 16-bit random integer. | 152 | /// Generates a cryptographically strong 16-bit random integer. |
| 153 | /// </summary> | 153 | /// </summary> |
| 154 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 154 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 155 | public static short Int16 | 155 | public static short Int16 |
| 156 | { | 156 | { |
| 157 | get | 157 | get |
| 158 | { | 158 | { |
| 159 | byte[] value = new byte[2]; | 159 | byte[] value = new byte[2]; |
| 160 | | 160 | |
| 161 | s_randomNumberGenerator.GetBytes(value); | 161 | RandomNumberGenerator.GetBytes(value); |
| 162 | | 162 | |
| 163 | return BitConverter.ToInt16(value, 0); | 163 | return BitConverter.ToInt16(value, 0); |
| 164 | } | 164 | } |
| @@ -167,7 +167,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 167 | /// <summary> | 167 | /// <summary> |
| 168 | /// Generates a cryptographically strong 16-bit random integer between specified values. | 168 | /// Generates a cryptographically strong 16-bit random integer between specified values. |
| 169 | /// </summary> | 169 | /// </summary> |
| 170 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 170 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 171 | /// <param name="startNumber">A <see cref="short"/> that is the low end of our range.</param> | 171 | /// <param name="startNumber">A <see cref="short"/> that is the low end of our range.</param> |
| 172 | /// <param name="stopNumber">A <see cref="short"/> that is the high end of our range.</param> | 172 | /// <param name="stopNumber">A <see cref="short"/> that is the high end of our range.</param> |
| 173 | /// <returns>A <see cref="short"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 173 | /// <returns>A <see cref="short"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -182,14 +182,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 182 | /// <summary> | 182 | /// <summary> |
| 183 | /// Generates a cryptographically strong unsigned 16-bit random integer. | 183 | /// Generates a cryptographically strong unsigned 16-bit random integer. |
| 184 | /// </summary> | 184 | /// </summary> |
| 185 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 185 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 186 | public static ushort UInt16 | 186 | public static ushort UInt16 |
| 187 | { | 187 | { |
| 188 | get | 188 | get |
| 189 | { | 189 | { |
| 190 | byte[] value = new byte[2]; | 190 | byte[] value = new byte[2]; |
| 191 | | 191 | |
| 192 | s_randomNumberGenerator.GetBytes(value); | 192 | RandomNumberGenerator.GetBytes(value); |
| 193 | | 193 | |
| 194 | return BitConverter.ToUInt16(value, 0); | 194 | return BitConverter.ToUInt16(value, 0); |
| 195 | } | 195 | } |
| @@ -198,7 +198,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 198 | /// <summary> | 198 | /// <summary> |
| 199 | /// Generates a cryptographically strong unsigned 16-bit random integer between specified values. | 199 | /// Generates a cryptographically strong unsigned 16-bit random integer between specified values. |
| 200 | /// </summary> | 200 | /// </summary> |
| 201 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 201 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 202 | /// <param name="startNumber">A <see cref="ushort"/> that is the low end of our range.</param> | 202 | /// <param name="startNumber">A <see cref="ushort"/> that is the low end of our range.</param> |
| 203 | /// <param name="stopNumber">A <see cref="ushort"/> that is the high end of our range.</param> | 203 | /// <param name="stopNumber">A <see cref="ushort"/> that is the high end of our range.</param> |
| 204 | /// <returns>A <see cref="ushort"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 204 | /// <returns>A <see cref="ushort"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -213,14 +213,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 213 | /// <summary> | 213 | /// <summary> |
| 214 | /// Generates a cryptographically strong 24-bit random integer. | 214 | /// Generates a cryptographically strong 24-bit random integer. |
| 215 | /// </summary> | 215 | /// </summary> |
| 216 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 216 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 217 | public static Int24 Int24 | 217 | public static Int24 Int24 |
| 218 | { | 218 | { |
| 219 | get | 219 | get |
| 220 | { | 220 | { |
| 221 | byte[] value = new byte[3]; | 221 | byte[] value = new byte[3]; |
| 222 | | 222 | |
| 223 | s_randomNumberGenerator.GetBytes(value); | 223 | RandomNumberGenerator.GetBytes(value); |
| 224 | | 224 | |
| 225 | return Int24.GetValue(value, 0); | 225 | return Int24.GetValue(value, 0); |
| 226 | } | 226 | } |
| @@ -229,7 +229,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 229 | /// <summary> | 229 | /// <summary> |
| 230 | /// Generates a cryptographically strong 24-bit random integer between specified values. | 230 | /// Generates a cryptographically strong 24-bit random integer between specified values. |
| 231 | /// </summary> | 231 | /// </summary> |
| 232 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 232 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 233 | /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> | 233 | /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> |
| 234 | /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> | 234 | /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> |
| 235 | /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 235 | /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -244,14 +244,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 244 | /// <summary> | 244 | /// <summary> |
| 245 | /// Generates a cryptographically strong unsigned 24-bit random integer. | 245 | /// Generates a cryptographically strong unsigned 24-bit random integer. |
| 246 | /// </summary> | 246 | /// </summary> |
| 247 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 247 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 248 | public static UInt24 UInt24 | 248 | public static UInt24 UInt24 |
| 249 | { | 249 | { |
| 250 | get | 250 | get |
| 251 | { | 251 | { |
| 252 | byte[] value = new byte[3]; | 252 | byte[] value = new byte[3]; |
| 253 | | 253 | |
| 254 | s_randomNumberGenerator.GetBytes(value); | 254 | RandomNumberGenerator.GetBytes(value); |
| 255 | | 255 | |
| 256 | return UInt24.GetValue(value, 0); | 256 | return UInt24.GetValue(value, 0); |
| 257 | } | 257 | } |
| @@ -260,7 +260,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 260 | /// <summary> | 260 | /// <summary> |
| 261 | /// Generates a cryptographically strong unsigned 24-bit random integer between specified values. | 261 | /// Generates a cryptographically strong unsigned 24-bit random integer between specified values. |
| 262 | /// </summary> | 262 | /// </summary> |
| 263 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 263 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 264 | /// <param name="startNumber">A <see cref="UInt24"/> that is the low end of our range.</param> | 264 | /// <param name="startNumber">A <see cref="UInt24"/> that is the low end of our range.</param> |
| 265 | /// <param name="stopNumber">A <see cref="UInt24"/> that is the high end of our range.</param> | 265 | /// <param name="stopNumber">A <see cref="UInt24"/> that is the high end of our range.</param> |
| 266 | /// <returns>A <see cref="UInt24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 266 | /// <returns>A <see cref="UInt24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -275,14 +275,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 275 | /// <summary> | 275 | /// <summary> |
| 276 | /// Generates a cryptographically strong 32-bit random integer. | 276 | /// Generates a cryptographically strong 32-bit random integer. |
| 277 | /// </summary> | 277 | /// </summary> |
| 278 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 278 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 279 | public static int Int32 | 279 | public static int Int32 |
| 280 | { | 280 | { |
| 281 | get | 281 | get |
| 282 | { | 282 | { |
| 283 | byte[] value = new byte[4]; | 283 | byte[] value = new byte[4]; |
| 284 | | 284 | |
| 285 | s_randomNumberGenerator.GetBytes(value); | 285 | RandomNumberGenerator.GetBytes(value); |
| 286 | | 286 | |
| 287 | return BitConverter.ToInt32(value, 0); | 287 | return BitConverter.ToInt32(value, 0); |
| 288 | } | 288 | } |
| @@ -291,7 +291,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 291 | /// <summary> | 291 | /// <summary> |
| 292 | /// Generates a cryptographically strong 32-bit random integer between specified values. | 292 | /// Generates a cryptographically strong 32-bit random integer between specified values. |
| 293 | /// </summary> | 293 | /// </summary> |
| 294 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 294 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 295 | /// <param name="startNumber">A <see cref="int"/> that is the low end of our range.</param> | 295 | /// <param name="startNumber">A <see cref="int"/> that is the low end of our range.</param> |
| 296 | /// <param name="stopNumber">A <see cref="int"/> that is the high end of our range.</param> | 296 | /// <param name="stopNumber">A <see cref="int"/> that is the high end of our range.</param> |
| 297 | /// <returns>A <see cref="int"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 297 | /// <returns>A <see cref="int"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -306,14 +306,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 306 | /// <summary> | 306 | /// <summary> |
| 307 | /// Generates a cryptographically strong unsigned 32-bit random integer. | 307 | /// Generates a cryptographically strong unsigned 32-bit random integer. |
| 308 | /// </summary> | 308 | /// </summary> |
| 309 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 309 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 310 | public static uint UInt32 | 310 | public static uint UInt32 |
| 311 | { | 311 | { |
| 312 | get | 312 | get |
| 313 | { | 313 | { |
| 314 | byte[] value = new byte[4]; | 314 | byte[] value = new byte[4]; |
| 315 | | 315 | |
| 316 | s_randomNumberGenerator.GetBytes(value); | 316 | RandomNumberGenerator.GetBytes(value); |
| 317 | | 317 | |
| 318 | return BitConverter.ToUInt32(value, 0); | 318 | return BitConverter.ToUInt32(value, 0); |
| 319 | } | 319 | } |
| @@ -322,7 +322,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 322 | /// <summary> | 322 | /// <summary> |
| 323 | /// Generates a cryptographically strong unsigned 32-bit random integer between specified values. | 323 | /// Generates a cryptographically strong unsigned 32-bit random integer between specified values. |
| 324 | /// </summary> | 324 | /// </summary> |
| 325 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 325 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 326 | /// <param name="startNumber">A <see cref="uint"/> that is the low end of our range.</param> | 326 | /// <param name="startNumber">A <see cref="uint"/> that is the low end of our range.</param> |
| 327 | /// <param name="stopNumber">A <see cref="uint"/> that is the high end of our range.</param> | 327 | /// <param name="stopNumber">A <see cref="uint"/> that is the high end of our range.</param> |
| 328 | /// <returns>A <see cref="uint"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 328 | /// <returns>A <see cref="uint"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -337,14 +337,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 337 | /// <summary> | 337 | /// <summary> |
| 338 | /// Generates a cryptographically strong 64-bit random integer. | 338 | /// Generates a cryptographically strong 64-bit random integer. |
| 339 | /// </summary> | 339 | /// </summary> |
| 340 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 340 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 341 | public static long Int64 | 341 | public static long Int64 |
| 342 | { | 342 | { |
| 343 | get | 343 | get |
| 344 | { | 344 | { |
| 345 | byte[] value = new byte[8]; | 345 | byte[] value = new byte[8]; |
| 346 | | 346 | |
| 347 | s_randomNumberGenerator.GetBytes(value); | 347 | RandomNumberGenerator.GetBytes(value); |
| 348 | | 348 | |
| 349 | return BitConverter.ToInt64(value, 0); | 349 | return BitConverter.ToInt64(value, 0); |
| 350 | } | 350 | } |
| @@ -353,7 +353,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 353 | /// <summary> | 353 | /// <summary> |
| 354 | /// Generates a cryptographically strong 64-bit random integer between specified values. | 354 | /// Generates a cryptographically strong 64-bit random integer between specified values. |
| 355 | /// </summary> | 355 | /// </summary> |
| 356 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 356 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 357 | /// <param name="startNumber">A <see cref="long"/> that is the low end of our range.</param> | 357 | /// <param name="startNumber">A <see cref="long"/> that is the low end of our range.</param> |
| 358 | /// <param name="stopNumber">A <see cref="long"/> that is the high end of our range.</param> | 358 | /// <param name="stopNumber">A <see cref="long"/> that is the high end of our range.</param> |
| 359 | /// <returns>A <see cref="long"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 359 | /// <returns>A <see cref="long"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |
| @@ -368,14 +368,14 @@ namespace GSF.Security.Cryptography · 8 unmodified lines |
| 368 | /// <summary> | 368 | /// <summary> |
| 369 | /// Generates a cryptographically strong unsigned 64-bit random integer. | 369 | /// Generates a cryptographically strong unsigned 64-bit random integer. |
| 370 | /// </summary> | 370 | /// </summary> |
| 371 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 371 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 372 | public static ulong UInt64 | 372 | public static ulong UInt64 |
| 373 | { | 373 | { |
| 374 | get | 374 | get |
| 375 | { | 375 | { |
| 376 | byte[] value = new byte[8]; | 376 | byte[] value = new byte[8]; |
| 377 | | 377 | |
| 378 | s_randomNumberGenerator.GetBytes(value); | 378 | RandomNumberGenerator.GetBytes(value); |
| 379 | | 379 | |
| 380 | return BitConverter.ToUInt64(value, 0); | 380 | return BitConverter.ToUInt64(value, 0); |
| 381 | } | 381 | } |
| @@ -384,7 +384,7 @@ namespace GSF.Security.Cryptography · 2 unmodified lines |
| 384 | /// <summary> | 384 | /// <summary> |
| 385 | /// Generates a cryptographically strong unsigned 64-bit random integer between specified values. | 385 | /// Generates a cryptographically strong unsigned 64-bit random integer between specified values. |
| 386 | /// </summary> | 386 | /// </summary> |
| 387 | /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> | 387 | /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> |
| 388 | /// <param name="startNumber">A <see cref="ulong"/> that is the low end of our range.</param> | 388 | /// <param name="startNumber">A <see cref="ulong"/> that is the low end of our range.</param> |
| 389 | /// <param name="stopNumber">A <see cref="ulong"/> that is the high end of our range.</param> | 389 | /// <param name="stopNumber">A <see cref="ulong"/> that is the high end of our range.</param> |
| 390 | /// <returns>A <see cref="ulong"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> | 390 | /// <returns>A <see cref="ulong"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> |