I would like to shuffle 4 numbers randomly in visual basic. These represent the 4 answers to a multiple choice question that I want to present in a different order every time. I have found the following code, but I cannot work out what the input and output variables are:
Public Sub Shuffle(Of T)(ByRef A() As T)
Dim last As Integer = A.Length - 1
Dim B(last) As T
Dim done(last) As Byte
Dim r As New Random(My.Computer.Clock.TickCount)
Dim n As Integer
For i As Integer = 0 To last
Do
n = r.Next(last + 1)
Loop Until Not done(n)
done(n) = 1
B(i) = A(n)
Next
A = B
End Sub
Thanks for any help.
Aucun commentaire:
Enregistrer un commentaire