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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:52:11+00:00 2026-06-15T16:52:11+00:00

I’m new to stack overflow and I’m learning a new language which is vb.net.

  • 0

I’m new to stack overflow and I’m learning a new language which is vb.net. I’m working on a first app that need the use of a database, and what i’m trying to do is taking every entries in a column, putting them in an array, suffle the array and then putting back the new array in the column of the database. Sort of a names in a hat application.. I don’t have any code right now, I’m doing my lessons first and I do search many forums and I have already many pieces of the puzzle like the randomize array, database handling.. My problem is that I don’t find any code to prevent data to get the same order after the shuffle for an example:

Let’s pretend I have 4 entries in my database:
Sarah, james, alex, daniel.

When suffling the array, how can I prevent sarah to comes first, and or james second, etc..

If you could just give me a point to start.. As I told you I’m starting to learn this language and I don’t want you guys to write the app for me but just having a little clue will be much apreciate. I check lessons online but I’m getting a little bored with begginers course and the “hello world” first app demonstration so.. I think I’m ready for the next step!

  • 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-15T16:52:12+00:00Added an answer on June 15, 2026 at 4:52 pm

    @Steven got a valid point. But I think you can even go without adding the SortIndex, because you can shuffle results directly in your query, like this (assuming your backend is MSSQL):

    SELECT * FROM table1 ORDER BY NEWID()
    

    If still necessary, here is how an array can be shuffled programmatically:

    Dim a() As String = {"Sarah", "James", "Alex", "Daniel"}
    Dim shuffledList As New List(Of String)
    Randomize()
    For i = 0 To UBound(a)
      Dim allowedValues() As String = a.Except(shuffledList).ToArray
      shuffledList.Add(allowedValues(Math.Floor(Rnd() * allowedValues.Count)))
    Next
    

    If you want to make sure original order is not repeated for any of the elements, use this code instead:

    Dim a() As String = {"Sarah", "James", "Alex", "Daniel"}
    Dim ub As Integer = UBound(a)
    Dim shuffledList As New List(Of String)
    Randomize()
    For i = 0 To ub
      Dim allowedValues() As String = a.Except(shuffledList).Except({a(i)}).ToArray
      Dim randomValue As String
      If i = ub - 1 And allowedValues.Contains(a(ub)) Then
        randomValue = a(ub)
      Else
        randomValue = allowedValues(Math.Floor(Rnd() * allowedValues.Count))
      End If
      shuffledList.Add(randomValue)
    Next
    

    Here the most important part is where the item before the last one is forced to be the last item, if the last item was not already picked. This is to make sure last item goes somewhere except the last position, otherwise there is nothing to pick from in the last step. Overall, the sequence appears to be randomly sorted and it’s guaranteed that item #1 will not be #1, #2 will not be #2 etc. The algorithm always ends in N steps, where N is the number of items.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.