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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:01:36+00:00 2026-05-26T18:01:36+00:00

I have a standard deck of 52 cards is represented in an array. Each

  • 0

I have a standard deck of 52 cards is represented in an array. Each card is represented as an integer. I wrote the below function to shuffle the cards. Does the code below look ok?

Module Module3

Sub Main()

    ' initialize array
    Dim Cards(52) As Integer

    ' Unit Test
    ' Pass array as argument.
    Console.WriteLine(shuffle(Cards))

End Sub

Function shuffle(ByVal Cards() As Integer)

    Dim counter = 1
    Dim rand = New Random()

    For Each card In Cards

        ' Grab random number with range of 52
        Dim n = rand.Next(52)

        ' Pick a card
        Dim temp = Cards(counter)

        ' Swap picked card with random card
        Cards(counter) = Cards(n)
        Cards(n) = temp

        counter += 1

    Next

    Return (Cards)

End Function

End Module
  • 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-26T18:01:37+00:00Added an answer on May 26, 2026 at 6:01 pm

    No, the code doesn’t do what you say.

    Dim Cards(52) As Integer
    

    This will create an array for 53 cards, not 52. Use:

    Dim Cards(51) As Integer
    

    When shuffling, swap each card with a card earlier in the deck (or itself), not anywhere in the deck. (This is the principle of the Fisher-Yates shuffle.)

    Instead of having a counter separate from the loop, use the counter for the looping.

    Dim rand = New Random()
    
    For counter = 0 to Cards.Length - 1
    
      Dim n = rand.Next(counter + 1)
    
      Dim temp = Cards(counter)
      Cards(counter) = Cards(n)
      Cards(n) = temp
    
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standard deck of cards and then have removed a few, from
I have standard source code package under Linux which requires to run ./configure make
Does Java have standard functions for security like in php htmlspecialchars , strip_tags ?
Here's what I have: Standard Deviation Mean See code double[] series = { 150,
I have a standard code to call a .net webservice I get exception org.xmlpull.v1.xmlpullparserexception
I have a Deck object (deck of cards) which is a double-ended queue implemented
I have standard page layout: header + 2 blocks (left and right). Code are
I've heard they have standard GUI guideline, but I can't seem to find a
I have a mobile site running with jQuery Mobile. I want to have standard
I have a standard textbox and I've got jQuery on the page. I want

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.