Created
June 9, 2014 16:42
-
-
Save anonymous/ccb5a6e34752342cfcf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
namespace ConsoleApplication1 | |
{ | |
public class Program | |
{ | |
static void Main() | |
{ | |
var positive = new BitArray(int.MaxValue); | |
var negative = new BitArray(int.MaxValue); | |
var collisionFound = false; | |
var iterations = 0; | |
while (!collisionFound) | |
{ | |
iterations++; | |
var guid = Guid.NewGuid(); | |
var hashcode = guid.GetHashCode(); | |
var which = hashcode >= 0 ? positive : negative; | |
hashcode = Math.Abs(hashcode); | |
if (which[hashcode]) | |
{ | |
collisionFound = true; | |
} | |
which[hashcode] = true; | |
} | |
Console.WriteLine("Collision found in {0} iterations", iterations); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment