MsgBox(64,
"随机数"
, _Random(1))
MsgBox(64,
"随机数"
, _Random(10))
MsgBox(64,
"随机数"
, _Random(100))
MsgBox(64,
"随机数"
, _Random(1000))
MsgBox(64,
"随机数"
, _Random(10000))
;;产生随机数函数
Func _Random($nNum1 = 0, $nNum2 = 0, $iFlag = 0)
; Invalid 1st parameter
If Not IsNumber($nNum1) Then Return SetError(1, 0, 0)
Switch @NumParams
Case 0
Return Random()
Case 1
If $nNum1 < 0 Then Return -Random(-$nNum1)
Return Random($nNum1)
Case Else
; Invalid 2nd or 3rd parameter
If Not IsNumber($nNum1) Or ($iFlag <> 0 And $iFlag <> 1) Then Return SetError(2, 0, 0)
If $nNum1 = $nNum2 Then Return $nNum1
If $nNum2 > $nNum1 Then Return Random($nNum1, $nNum2, $iFlag)
Return Random($nNum2, $nNum1, $iFlag)
EndSwitch
EndFunc