- 版本 v1.1.15.01
- 指南和概述
- 常见问题(FAQ)
- 按字母排序的命令和函数索引
- AutoHotkey 脚本展示
- 变更和新功能
- 基本用法和语法
- 迁移到 AutoHotkey 1.1(AutoHotkey_L)
- 环境管理
- 本机代码互操作
- 文件、目录和磁盘管理
- Drive
- DriveGet
- DriveSpaceFree
- FileAppend
- FileCopy
- FileCopyDir
- FileCreateDir
- FileCreateShortcut
- FileDelete
- FileEncoding [AHK_L 42+]
- FileGetAttrib
- FileGetShortcut
- FileGetSize
- FileGetTime
- FileGetVersion
- FileInstall
- FileMove
- FileMoveDir
- FileOpen [AHK_L 42+]
- FileReadLine
- FileRead
- FileRecycle
- FileRecycleEmpty
- FileRemoveDir
- FileSelectFile
- FileSelectFolder
- FileSetAttrib
- FileSetTime
- IfExist / IfNotExist
- IniDelete
- IniRead
- IniWrite
- Loop(文件和文件夹)
- Loop(读取文件内容)
- SetWorkingDir
- SplitPath
- 流程控制
- 内置函数
- GUI、MsgBox、InputBox 及其他对话框
- 鼠标和键盘
- 鼠标和键盘
- #InstallKeybdHook
- #InstallMouseHook
- #KeyHistory
- BlockInput
- Click [v1.0.43+]
- ControlClick
- ControlSend / ControlSendRaw
- CoordMode
- GetKeyState
- KeyHistory
- KeyWait
- Input
- MouseClick
- MouseClickDrag
- MouseGetPos
- MouseMove
- Send / SendRaw / SendInput / SendPlay / SendEvent: 发送按键和点击
- SendLevel [v1.1.06+]
- SendMode [v1.0.43+]
- SetDefaultMouseSpeed
- SetKeyDelay
- SetMouseDelay
- SetCapsLockState/SetNumLockState/SetScrollLockState
- SetStoreCapslockMode
- 数学相关
- 屏幕管理
- 杂项命令
- 进程管理
- 注册表管理
- 声音命令
- 字符串管理
- 窗口管理
- 控件
- 窗口组
- #WinActivateForce
- DetectHiddenText
- DetectHiddenWindows
- SetTitleMatchMode
- SetWinDelay
- StatusBarGetText
- StatusBarWait
- WinActivate
- WinActivateBottom
- WinClose
- WinGet
- WinGetActiveStats
- WinGetActiveTitle
- WinGetClass
- WinGetPos
- WinGetText
- WinGetTitle
- WinHide
- WinKill
- WinMaximize
- WinMinimize
- WinMinimizeAll / WinMinimizeAllUndo
- WinMove
- WinRestore
- WinSet
- WinSetTitle
- WinShow
- WinWait
- WinWaitActive / WinWaitNotActive
- WinWaitClose
- #指令
Random
生成伪随机数。
Random, OutputVar [, Min, Max] Random, , NewSeed
参数
- OutputVar
用来存储结果的变量名. 存储的浮点数的格式由 SetFormat 决定.
- Min
- 可以生成的最小数字, 可以为负数, 浮点数或 表达式. 如果省略, 最小的数字默认为 0. 允许的最小整数值为 -2147483648, 但浮点数没有限制.
- Max
可以生成的最大数字, 可以为负数, 浮点数或 表达式. 如果省略, 最大的数字默认为 2147483647 (这也是允许的最大整数值, 但浮点数没有限制).
- NewSeed
此模式使用 NewSeed 重新设定随机数生成器的种子 (可以为 表达式). 这会影响后续生成的所有随机数. NewSeed 应该为介于 0 和 4294967295 (0xFFFFFFFF) 之间的整数. 重新设定种子可以提高随机数的质量/安全性, 尤其当 NewSeed 是真正的随机数而不是质量不佳的伪随机数时. 重新设定种子通常只需要进行一次.
如果脚本没有重新设定种子, 则使用自 1601 年 1 月 1 日开始 100 纳秒间隔数目的 64 位值的低 32 位作为种子开始. 这个值在 ~7.2 分钟内从 0 变化到 4294967295.
备注
此命令生成伪随机数, 即一个模拟真正随机数的数字, 但它实际上是通过复杂的公式计算使得判断/猜测下一个数字极为困难的数字.
在指定范围中所有数字被生成的机率几乎是相同的 (然而, 请参阅下面的 "已知限制").
如果 Min 或 Max 其中一个为小数,则最后结果将为由 SetFormat 设置格式的浮点数。否则,结果为整数。
结果为浮点数的已知限制: 1) 对于任何特殊的范围只能生成大约 4,294,967,296 个截然不同的数字, 所以永远不会生成范围中的其他所有数字; 2) 优势结果可能比指定的 Max 略大一些 (这种情况部分是由浮点数固有的不精确性导致的).
相关
示例
Random, rand, 1, 10 Random, rand, 0.0, 1.0
基于原始来源的注释
This function uses the Mersenne Twister random number generator, MT19937, written by Takuji Nishimura and Makoto Matsumoto, Shawn Cokus, Matthe Bellew and Isaku Wada.
The Mersenne Twister is an algorithm for generating random numbers. It was designed with consideration of the flaws in various other generators. The period, 219937-1, and the order of equidistribution, 623 dimensions, are far greater. The generator is also fast; it avoids multiplication and division, and it benefits from caches and pipelines. For more information see the inventors' web page at www.math.keio.ac.jp/~matumoto/emt.html
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Do NOT use for CRYPTOGRAPHY without securely hashing several returned values together, otherwise the generator state can be learned after reading 624 consecutive values.
When you use this, send an email to: matumoto@math.keio.ac.jp with an appropriate reference to your work. It would be nice to CC: rjwagner@writeme.com and Cokus@math.washington.edu when you write.
This above has been already been done for AutoHotkey, but if you use the Random command in a publicly distributed application, consider sending an e-mail to the above people to thank them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论