【发布时间】:2015-03-31 01:01:18
【问题描述】:
我正在 vb.net 中开发一个网页,该网页将为用户生成许多多项选择题。我需要对已经放入数组中的四个答案进行洗牌。让我们假设我必须关注数组:
array = {"Correct", "Wrong1", "Wrong2", "Wrong3"}
我尝试使用以下方法:
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
该功能工作得很好,但我的问题是,如果我有四个问题,每个问题的答案将被打乱,但正确答案将在一个位置,例如:
array = {"Wrong1", "Correct", "Wrong2", "Wrong3"}
array = {"Wrong2", "Correct", "Wrong3", "Wrong1"}
array = {"Wrong3", "Correct", "Wrong1", "Wrong2"}
array = {"Wrong1", "Correct", "Wrong3", "Wrong2"}
我需要的是将其位置从一个问题更改为另一个问题的正确答案。 感谢您的帮助。
【问题讨论】: