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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:17:34+00:00 2026-06-16T03:17:34+00:00

Possible Duplicate: Generating random string in T-SQL I need to convert this C# method

  • 0

Possible Duplicate:
Generating random string in T-SQL

I need to convert this C# method in T-SQL:

 public static string GenerateRandomID(int size)
    {
        StringBuilder pass = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < size; i++)
        {
            int binary = random.Next(0, 2);
            switch (binary)
            {
                case 0:
                    char ch = (Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))));
                    pass.Append(ch);
                    break;
                case 1:
                    int num = random.Next(1, 10);
                    pass.Append(num);
                    break;
            }
        }
        return pass.ToString();
    }

Usage example: string output = GenerateRandomID(15)

output should look like: O1REGVIDK7T4R9R

Someone have an idea…

  • 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-16T03:17:35+00:00Added an answer on June 16, 2026 at 3:17 am
    create proc GenerateRandomID
        @size       int
    as
    begin
    
        declare @chars char(26) = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        declare @i int = 0
        declare @id varchar(max) = ''
    
        while @i < @size
        begin
            if rand() > .5
                set @id = @id + substring(@chars, cast(ceiling(rand() * 26) as int), 1)
            else
                set @id = @id + cast(floor(rand() * 10) as varchar(2))
            set @i = @i + 1
        end
    
        select @id
    
    end
    go
    
    
    
    exec GenerateRandomID 15
    
    -------------------
    BWZBKR601I8Z9KV
    
    (1 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Generating random strings with T-SQL I need to generate a random string
Possible Duplicate: Generating random number in a range with Java This feels pretty silly,
Possible Duplicate: Creating a unique alphanumeric 10-character string I need to generate unique random
Possible Duplicate: XJC Generating Integer Instead of int Need to generate entity class with
Possible Duplicate: Generating random numbers effectively I need to generate random numbers in my
Possible Duplicate: python random string generation with upper case letters and digits I need
Possible Duplicate: Java: generating random number in a range I need a little help.
Possible Duplicate: Algorithm for generating a random number Hi i need to assign a
Possible Duplicate: generating random numbers from skewed normal distribution i expect a long array
Possible Duplicate: Algorithm for generating a random number is posible to generate a random

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.