by Nithin Pradeep (1 Submission)
Category: Games
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (6 Votes)
Hi friends. This is a good card shuffling routine.
Basically, what it does is it takes an aray containing the numbers form 1 to 52 and shuffles the array. This can be used for any purpose including shuffling cards.
Inputs
An array which containd the numbers form 1 to 52 in that order
Assumes
This code works by choosing a random number between 1 & 52 and assigning it to an element of the array. Then it chooses another random number and assigns it to the next element. The code is pretty self explanatory. If you have some doubt, just mail me.
Code Returns
The same array with the order of the numbers shuffled
Dim deck(1 To 52) As Integer 'the array which holds the cards
'the following are just a few counters
Dim n As Integer
Dim temp As Integer
Dim i As Integer
Dim temp1 As Integer
'this statement is used to return different random numbers each time we run the application
Randomize Timer
'the following loop assigns the numbers 1 to 52 to the array in that order.
For n = 1 To 52
deck(n) = n
Next n
'time to do the shuffling
For i = 0 To 9'this llop just repeats the shuffling process 10 times
For temp = 1 To 52
n = Int((52 * Rnd) + 1) this generates a random number in the range 1 to 52
'the following block of code interchanges the values of deck(temp) & deck(n). This is a very simple method of shuffling the array. If you read it carefully you will be able to understabd the logic.
temp1 = deck(temp)
deck(temp) = deck(n)
deck(n) = temp1
Next temp
Next i
No comments have been posted about A cool card shuffling routine 'without using condition statements'. Why not be the first to post a comment about A cool card shuffling routine 'without using condition statements'.