I am developing a web page in vb.net that will generate the user several questions with several choices. I need to shuffle four answers that are already placed in an array. Suppose I have the following array:
array = {"Correct", "Wrong1", "Wrong2", "Wrong3"}
I tried using the following method:
Public Shared Function Shuffle(ByVal items() As String) As Array
Dim max_index As Integer = items.Length - 1
Dim rnd As New Random(DateTime.Now.Millisecond)
For i As Integer = 0 To max_index
' Pick an item for position i.
Randomize()
Dim j As Integer = rnd.Next(i, max_index)
' Swap them.
Dim temp As String = items(i)
items(i) = items(j)
items(j) = temp
Next i
Return items
End Function
The function works very well, but my problem is that if I have four questions, the answers will be shuffled for each question, but the correct answer will be in one position:
array = {"Wrong1", "Correct", "Wrong2", "Wrong3"}
array = {"Wrong2", "Correct", "Wrong3", "Wrong1"}
array = {"Wrong3", "Correct", "Wrong1", "Wrong2"}
array = {"Wrong1", "Correct", "Wrong3", "Wrong2"}
I need the right answer to change my location from one question to another. Your help is appreciated.
source
share