Do you want to randomize the items in an array with VB.net? Add these 2 functions below to your code to get it working. The reason there’s 2 functions you must add is because the first function is using the second function to make it all work.
To use it, you just type: Shuffle(YourArray, 5)
The number is just how many times it’s going to shuffle the array, you can use whatever you want here.
Here is the code for the 2 functions:
Public Function Shuffle(ByRef arrayToBeShuffled As Array, ByVal numberOfTimesToShuffle As Integer)
Dim rndPosition As New Random(DateTime.Now.Millisecond)
For i As Integer = 1 To numberOfTimesToShuffle
For i2 As Integer = 1 To arrayToBeShuffled.Length
Swap(arrayToBeShuffled(rndPosition.Next(0, arrayToBeShuffled.Length)), arrayToBeShuffled(rndPosition.Next(0, arrayToBeShuffled.Length)))
Next i2
Next i
Return ("")
End Function
Public Function Swap(ByRef arg1 As Object, ByRef arg2 As Object)
Dim strTemp As String
strTemp = arg1
arg1 = arg2
arg2 = strTemp
Return ("")
End Function
More articles you may find interesting...
Get Latest Post In WordPress (Tiny PHP Code)
Here’s a useful code snippet in PHP for WordPress to get a ...
Here’s a useful code snippet in PHP for WordPress to get a ...
Make WordPress use HTTPS & WWW & block XMLRPC (.htaccess)
A while back I posted some ".htaccess" code to add HTTPS (SS...
A while back I posted some ".htaccess" code to add HTTPS (SS...
Microsoft Virtual Pc 2007 - Run Another Operative System Inside Your Current Operative System
Microsoft Virtual PC 2007 - Run Another Operative System Ins...
Microsoft Virtual PC 2007 - Run Another Operative System Ins...