Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 436615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:29:44+00:00 2026-05-12T20:29:44+00:00

I’d like to prove that a GUID is not unique in a simple test

  • 0

I’d like to prove that a GUID is not unique in a simple test program.
I expected the following code to run for hours, but it’s not working. How can I make it work?

BigInteger begin = new BigInteger((long)0);
BigInteger end = new BigInteger("340282366920938463463374607431768211456",10);  //2^128
for(begin; begin<end; begin++)
  Console.WriteLine(System.Guid.NewGuid().ToString());

I’m using C#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:29:45+00:00Added an answer on May 12, 2026 at 8:29 pm

    Kai, I have provided a program that will do what you want using threads. It is licensed under the following terms: you must pay me $0.0001 per hour per CPU core you run it on. Fees are payable at the end of each calendar month. Please contact me for my paypal account details at your earliest convenience.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace GuidCollisionDetector
    {
        class Program
        {
            static void Main(string[] args)
            {
                //var reserveSomeRam = new byte[1024 * 1024 * 100];     // This indeed has no effect.
    
                Console.WriteLine("{0:u} - Building a bigHeapOGuids.", DateTime.Now);
                // Fill up memory with guids.
                var bigHeapOGuids = new HashSet<Guid>();
                try
                {
                    do
                    {
                        bigHeapOGuids.Add(Guid.NewGuid());
                    } while (true);
                }
                catch (OutOfMemoryException)
                {
                    // Release the ram we allocated up front.
                    // Actually, these are pointless too.
                    //GC.KeepAlive(reserveSomeRam);
                    //GC.Collect();
                }
                Console.WriteLine("{0:u} - Built bigHeapOGuids, contains {1} of them.", DateTime.Now, bigHeapOGuids.LongCount());
    
    
                // Spool up some threads to keep checking if there's a match.
                // Keep running until the heat death of the universe.
                for (long k = 0; k < Int64.MaxValue; k++)
                {
                    for (long j = 0; j < Int64.MaxValue; j++)
                    {
                        Console.WriteLine("{0:u} - Looking for collisions with {1} thread(s)....", DateTime.Now, Environment.ProcessorCount);
                        System.Threading.Tasks.Parallel.For(0, Int32.MaxValue, (i) =>
                        {
                            if (bigHeapOGuids.Contains(Guid.NewGuid()))
                                throw new ApplicationException("Guids collided! Oh my gosh!");
                        }
                        );
                        Console.WriteLine("{0:u} - That was another {1} attempts without a collision.", DateTime.Now, ((long)Int32.MaxValue) * Environment.ProcessorCount);
                    }
                }
                Console.WriteLine("Umm... why hasn't the universe ended yet?");
            }
        }
    }
    

    PS: I wanted to try out the Parallel extensions library. That was easy.

    And using OutOfMemoryException as control flow just feels wrong.

    EDIT

    Well, it seems this still attracts votes. So I’ve fixed the GC.KeepAlive() issue. And changed it to run with C# 4.

    And to clarify my support terms: support is only available on the 28/Feb/2010. Please use a time machine to make support requests on that day only.

    EDIT 2
    As always, the GC does a better job than I do at managing memory; any previous attempts at doing it myself were doomed to failure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.