ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

isRandomSecure

blowdart random test

Source

private static RandomNumberGenerator rand = System.Security.Cryptography.RandomNumberGenerator.Create();

public static bool isRandomSecure(this int source)
{
    var data = new byte[4];
    rand.GetBytes(data);

    return source == ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
}

Example

var num = 10;
if( num.isRandomSecure() ) {
  Console.WriteLine("num is random");
}
else {
  Console.WriteLine("num is not random");
}

Author: Ben Adams

Submitted on: 4 aug. 2016

Language: C#

Type: int

Views: 3850