【已解决】已知5个数值,如何随机选出1个,然后下一次随机从另外4个选出,依次类推
本帖最后由 烟雨 于 2013-4-3 18:19 编辑已知5个数值,如何随机选出1个,然后下一次随机从另外4个选出,依次类推
5选1
然后4选1
然后3选1
然后2选1
然后1选1
选出来的数值不参与下一次的选择,高手来吧 #include <Array.au3>
Local $aNum
For $i = 0 To 4
$aNum[$i] = Random(1, 5) & "," & ($i + 1)
Next
_Arraysort($aNum)
For $i = 0 To 4
$aVar = StringSplit($aNum[$i], ",")
Msgbox(0, '', $aVar)
Next
Local $array=
Local $i
Local $str = ""
For $i = 0 To UBound($array)-1
$array[$i] = Random(0, 100, 1)
$str &= $array[$i] & ","
Next
$str =StringTrimRight($str, 1)
$str = "随机生成的数据:" & @CRLF & $str & @CRLF & @CRLF
Local $j
Local $index
Local $last = UBound($array)-1
Local $tmp
While $last>0
For $i=0 To $last
$str &= $array[$i] & ", "
Next
$str &= ",,,取出,,,"
$index = Random(0, $last, 1)
If $index <> $last Then
$tmp = $array[$last]
$array[$last] = $array[$index]
$array[$index] = $tmp
EndIf
$str &= $array[$last] & "," & @CRLF
$last -= 1
WEnd
MsgBox(0, "随机生成的数据", $str & $array[$last])
回复 3# veket_linux
膜拜
页:
[1]