Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2014 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ccb5a6e34752342cfcf9 to your computer and use it in GitHub Desktop.
Save anonymous/ccb5a6e34752342cfcf9 to your computer and use it in GitHub Desktop.
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