VB icon

A cool card shuffling routine 'without using condition statements'

Email
Submitted on: 1/25/2015 11:28:00 AM
By: Nithin Pradeep (from psc cd)  
Level: Beginner
User Rating: By 6 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 705
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: A cool card shuffling routine 'without using condition statements'
' Description: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.
' By: Nithin Pradeep (from psc cd)
'
' Inputs:An array which containd the numbers form 1 to 52 in that order
'
' Returns:The same array with the order of the numbers shuffled
'
' 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.
'**************************************

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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.