© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
25 replies
cesarz

❔ Unique Integer ID GEN from string input

Hi there, I've been trying to think of a unique integer ID generator but let's just say I'm not too good at this blobthumbsup
public ulong UniqueIdGen(string str)
{
    char[] chars = str.ToCharArray();
    ulong ID = 0;
    foreach (char c in chars)
        ID = 1000 * ID + c + 67;
    return ID;
}
public ulong UniqueIdGen(string str)
{
    char[] chars = str.ToCharArray();
    ulong ID = 0;
    foreach (char c in chars)
        ID = 1000 * ID + c + 67;
    return ID;
}

The one I made is quite simple and it just shifts all the characters by 67 (so that all int values of the characters (33 to 126) are in range of 100 to 193) and adds the numbers together (side by side, so 102 '+' 192 => 102192)
It works and the ID's are unique but the issue is quite obvious -> the ID's are way too long.
I could ignore the last 4 characters in my initial range (which are
{ | } ~
{ | } ~
) and I would be able to squeeze my range into 10 to 99, but still: for ulong that would mean a character length limit of 9... which is quite low.
I searched online for some unique integer ID generating algorithms but couldn't find anything useful for my case, or I'm just blind and didn't notice something that actually is useful.

Any help in form of advice or links is appreciated.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Short Unique Id
C#CC# / help
9mo ago
✅ Creating random & unique page id
C#CC# / help
16mo ago
How to generate a unique int from an arbitrary string?
C#CC# / help
8mo ago
Extracting string from string?
C#CC# / help
4y ago