實(shí)現(xiàn)代碼:
- MsgBox(64, "隨機(jī)數(shù)", _Random(1))
- MsgBox(64, "隨機(jī)數(shù)", _Random(10))
- MsgBox(64, "隨機(jī)數(shù)", _Random(100))
- MsgBox(64, "隨機(jī)數(shù)", _Random(1000))
- MsgBox(64, "隨機(jī)數(shù)", _Random(10000))
- ;;產(chǎn)生隨機(jī)數(shù)函數(shù)
- 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
版權(quán)聲明:文章圖片資源來(lái)源于網(wǎng)絡(luò),如有侵權(quán),請(qǐng)留言刪除!!!
評(píng)論