AutoIt3实现随机数算法

admin AutoIt3评论6902字数 867阅读模式
摘要

AutoIt3实现了产生随机数的算法,封装成函数_Random()后提供使用,通过调用该函数产生一定范围的随机数。

实现代码:

  1. MsgBox(64"随机数", _Random(1))  
  2. MsgBox(64"随机数", _Random(10))   
  3. MsgBox(64"随机数", _Random(100))   
  4. MsgBox(64"随机数", _Random(1000))   
  5. MsgBox(64"随机数", _Random(10000))   
  6.    
  7. ;;产生随机数函数  
  8. Func _Random($nNum1 = 0, $nNum2 = 0, $iFlag = 0)  
  9.     ; Invalid 1st parameter  
  10.     If Not IsNumber($nNum1) Then Return SetError(100)   
  11.     Switch @NumParams  
  12.         Case 0  
  13.             Return Random()  
  14.         Case 1  
  15.             If $nNum1 < 0 Then Return -Random(-$nNum1)  
  16.             Return Random($nNum1)  
  17.         Case Else  
  18.             ; Invalid 2nd or 3rd parameter  
  19.             If Not IsNumber($nNum1) Or ($iFlag <> 0 And $iFlag <> 1) Then Return SetError(200)   
  20.             If $nNum1 = $nNum2 Then Return $nNum1  
  21.             If $nNum2 > $nNum1 Then Return Random($nNum1, $nNum2, $iFlag)  
  22.             Return Random($nNum2, $nNum1, $iFlag)  
  23.     EndSwitch  
  24. EndFunc  

版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
admin
  • 本文由 发表于 2020年10月13日 20:23:43
  • 转载请务必保留本文链接:https://www.58pxe.com/6658.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: