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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:29:34+00:00 2026-05-16T15:29:34+00:00

I need to generate a lot of random 2 character strings for my application.

  • 0

I need to generate a lot of random 2 character strings for my application. it’s a VB console application. basically what I have tried for random strings is this:

  Private Function GenerateRandomString(ByVal intLenghtOfString As Integer) As String
    'Create a new StrinBuilder that would hold the random string.
    Dim randomString As New StringBuilder
    'Create a new instance of the class Random
    Dim randomNumber As Random = New Random
    'Create a variable to hold the generated charater.
    Dim appendedChar As Char
    'Create a loop that would iterate from 0 to the specified value of intLenghtOfString
    For i As Integer = 0 To intLenghtOfString
      'Generate the char and assign it to appendedChar
      appendedChar = Convert.ToChar(Convert.ToInt32(26 * randomNumber.NextDouble()) + 65)
      'Append appendedChar to randomString
      randomString.Append(appendedChar)
    Next
    'Convert randomString to String and return the result.
    Return randomString.ToString()
  End Function

AND THIS:

  Private Function RandomStringGenerator(ByVal intLen As Integer) As String

    Dim r As New Random()

    Dim i As Integer

    Dim strTemp As String = ""

    For i = 0 To intLen

      strTemp = strTemp & Chr(Int((26 * r.NextDouble()) + 65))

    Next

    Return r.Next

  End Function

But when run, it displays something like this:

SR  
SR  
SR  
SR  
SR  
SR  
SR  
SR  
SR  
SR  
BR  
BR  
BR  
BR  
BR  
BR  
BR  
KR  
KR  
KR  
KR

and so on.

What is going on? I thought that I used to, a long time ago, be able to just do random.Next.

  • 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-16T15:29:35+00:00Added an answer on May 16, 2026 at 3:29 pm

    I’ve run into similar issues before with the Random object. The problem is that when you instantiate Random it’s default seed value is the number of milliseconds since windows started up. And since you are generating random characters at several a millisecond you end up with the same seed number.

    Instead you should create a shared random object instead of instantiating a new one on each call.

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

Sidebar

Related Questions

I need to generate unique invoice numbers for my Access (2010) database. The numbers
I'm working on a project where I need to generate end-user documentation for a
I'm new to opengl and have been able to learn a lot on my
I have some code that consists of a lot (several hundreds of LOC) of
I want to create a basic app where you have 8 numbered buttons, with
Ok so here is what I need to do: I am reading in a
I have a PHP program that reads from the database and generated formatted sheets.
I need to maintain & improve an existing website and I am drowning in
I'm working on a poker analysis tool with the following use case: User create

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.