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 8297809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:32:48+00:00 2026-06-08T15:32:48+00:00

I want to generate a Uniq Number something like TMP-0001354, TMP will be always

  • 0

I want to generate a Uniq Number something like TMP-0001354, TMP will be always same only number will get change, which should not be get duplicate in table.

I want to a exp. code which should be in c#, I’ll call that function at the time of inserting the record in table. SQL server database I am using

I am trying this I don’t know will it work fine or not.

 private string RandomNumberGenerator()
    {
        int maxSize = 8;
        int minSize = 5;
        char[] chars = new char[62];
        string a;
        a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        chars = a.ToCharArray();
        int size = maxSize;
        byte[] data = new byte[1];
        RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
        crypto.GetNonZeroBytes(data);
        size = maxSize;
        data = new byte[size];
        crypto.GetNonZeroBytes(data);
        StringBuilder result = new StringBuilder(size);
        foreach (byte b in data)
        { result.Append(chars[b % (chars.Length - 1)]); }
        return result.ToString();
    }

Some one please help me.

  • 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-06-08T15:32:50+00:00Added an answer on June 8, 2026 at 3:32 pm

    For generate uniq number use this (the number can start with 0):

    string number_s = "TMP-" + RandomNumber(0, 9) + RandomNumber(0, 9) + RandomNumber(0, 9) + RandomNumber(0, 9) + RandomNumber(0, 9) + RandomNumber(0, 9) + RandomNumber(0, 9);
    

    or this (is shorter, but will begin with 1):

    string number_s = "TMP-" + RandomNumber(1000000, 9999999);
    

    This is the code for RandomNumber:

    private static readonly Random random = new Random();
            private static readonly object syncLock = new object();
            public int RandomNumber(int min, int max)
            {
                lock (syncLock)
                { // synchronize
                    return random.Next(min, max);
                }
            }
    

    It works nice for me. Hope that I helped you.

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

Sidebar

Related Questions

I want to generate a random floating point number between 0.000000000000000 and 0.999999999999999 .
I want to generate incremental receipt numbers like this format 00000001. Every time new
I want to generate heat map from a set of data which is latitude
I want to generate URL like.. It should include two IDs with employer and
I want to generate checkbox field using GridView and system will calculate how many
I want to generate a unordered list which contains tag for showing images in
Let's say I have a class of 30 students and want generate every possible
I want to generate a list of files where the name consists of ${filename}.${date}
I want to generate a random timestamp and add a random increment to it
I want to generate random integers between 0-9 (inclusive on both ends), but I

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.