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

  • SEARCH
  • Home
  • 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 6758041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:43:38+00:00 2026-05-26T13:43:38+00:00

Is there a way to generate every time a 100% new GUID without any

  • 0

Is there a way to generate every time a 100% new GUID without any chance to collide within entire application?

Since I cannot answer my question in eight hours, I come up with the solution:

internal static class GuidGenerator
{
    private static readonly HashSet<Guid> _guids = new HashSet<Guid>();

    internal static Guid GetOne()
    {
        Guid result;

        lock (_guids)
            while (!_guids.Add(result = Guid.NewGuid())) ;

        return result;
    }
    internal static void Utilize(Guid guid)
    {
        lock (_guids)
            _guids.Remove(guid);
    }
}

Is this code solves the problem within the app?

EDIT: Uh, its getting complicated. Thread safety kills the speed.

  • 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-26T13:43:39+00:00Added an answer on May 26, 2026 at 1:43 pm

    Sure. A GUID is just a 128-bit value. So use a 128-bit integer (e.g. represented by two ulong values) and increment it. When you’ve reached the maximum value for the 128-bit integer type, you’ve generated all possible GUIDs. For example:

    public IEnumerable<Guid> GetAllGuids()
    {
        unchecked
        {
            byte[] buffer = new byte[16];
            ulong x = 0UL;
            do
            {
               byte[] high = BitConverter.GetBytes(x);
               Array.Copy(high, 0, buffer, 0, 8);
               ulong y = 0UL;
               do
               {
                   y++;
                   byte[] low = BitConverter.GetBytes(y);
                   Array.Copy(low, 0, buffer, 8, 8);
                   yield return new Guid(buffer);
               } while (y != 0UL);
               x++;
            } while (x != 0UL);
        }
    }
    

    Notes:

    • This is definitely not as efficient as it might be.
    • Iterating over all possible ulong values is a pain – I don’t like using do...while…
    • As noted in comments, this will produce values which are not valid UUIDs

    Of course, this is in no way random…

    In practice, as others have mentioned, the chances of collisions from Guid.NewGuid are incredibly small.

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

Sidebar

Related Questions

Is there any way to generate project docs during automated builds? I'd like to
Is there a way to generate a DLL file from Visual Studio Express without
How to unit test JPA code? is there any way to generate Unit Test
Is there any way I can authenticate a Facebook user without requiring them to
Is there a way to generate random number on Windows by reading from a
Is there a way to generate a hash of a string so that the
Is there a way to generate Excel spreadsheets with Perl on Linux so that
Is there a way to generate a PHP Soap Client from a WSDL file?
is there a way to generate a boost uuid from a string like 988A00C4-79F3-46f9-98CD-D5AD4AA2A0FE
Is there a way to generate tables in tex format in R and then

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.