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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:01:47+00:00 2026-05-27T16:01:47+00:00

Dim aryName As String() = Nothing aryName = File.ReadAllLines(Application.StartupPath & \Random\fnames.txt) Dim randomWords As

  • 0
Dim aryName As String() = Nothing
aryName = File.ReadAllLines(Application.StartupPath & "\Random\fnames.txt")

Dim randomWords As New List(Of String)
For i = 0 To aryName.Length - 1
If randomWords.Contains(aryName(i)) = False Then
    randomWords.Add(aryName(i))
End If
Next

Dim random As New Random
Label2.Text = (randomWords(random.Next(0, randomWords.Count - 1)).ToString)

that code is supposed to take words from a txt file and then put them into a label, only problem is; the words are sometimes repeated. I only want each word to appear once but instead they appear multiple times.

  • 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-27T16:01:48+00:00Added an answer on May 27, 2026 at 4:01 pm

    You’re using the entire array of words every time you check for a random word. My understanding of random.Next() isn’t that it uses a different random number from 0-n each time it is called, but generates a new number from 0-n, which might repeat before n times has occurred.

    To fix this, adjust your array each time you use a word – move the one it found to the end and adjust your range-1.

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

Sidebar

Related Questions

Dim goodCustObjList As New List(Of CustomerObj) goodCustObjList = DataBLLModule.GetCustomerRecordList(String.Empty) Dim custList = From t
Dim x = GetType(List(Of )) 'valid statement Dim list As New List(Of String) Now
dim shell,x,y x=D:\d y=c.bat & x set shell=createobject(wscript.shell) shell.run y shell.run a.bat set shell=nothing
Consider: Dim line As String Using readFile As New StreamReader(SalesUpdateFile) While (line = readFile.ReadLine)
Here is the sample: Dim TestString As String = Hello, & Chr(0) & World
Dim usersInRole As String() = Roles.GetUsersInRole(HR_Base_Role) Dim Myusers As New MembershipUserCollection For Each UserName
Dim intChunkId As Integer = &H4D546864 Dim strChunkId As String = MThd Dim easiestWay
Dim customers As List(Of Customer) = New List(Of Customer) For Each mbi In fordContracts
Dim myDelims As String() = New String() {<beginning of record>} Dim split1 As String()
Dim List As New List(Of DateTime) Then in my button click event: If InputBookinglength.SelectedValue.ToString

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.