/docs/commands/Random.htm

http://autohotkey-chinese.googlecode.com/
HTML | 84 lines | 79 code | 5 blank | 0 comment | 0 complexity | 7f3e0a4dd6a3553b79afac6c08205403 MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Random</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <link href="../css/commands.css" rel="stylesheet" type="text/css">
  8. <link href="../css/print.css" rel="stylesheet" type="text/css" media="print">
  9. </head>
  10. <body>
  11. <h1>Random</h1>
  12. <p>产生一个伪随机数</p>
  13. <p class="CommandSyntax">Random, OutputVar [, Min, Max]<br>
  14. Random, , NewSeed</p>
  15. <h3>参数 </h3>
  16. <table border="1" width="100%" cellspacing="0" cellpadding="3" bordercolor="#C0C0C0">
  17. <tr>
  18. <td>OutputVar</td>
  19. <td>存储结果的变量名被存储的浮点数的格式由 <a href="SetFormat.htm">SetFormat</a> 决定</td>
  20. </tr>
  21. <tr>
  22. <td width="15%">Min</td>
  23. <td width="85%">可以产生的最小的数可以是负数浮点数或者一个 <a href="../Variables.htm#Expressions">expression</a> (表达式)缺省情况下产生的最小的数是 0
  24. 允许的最小整数是 -2147483648浮点数没有限制</td>
  25. </tr>
  26. <tr>
  27. <td>Max</td>
  28. <td>可以产生的最大的数可以是负数浮点数或者一个 <a href="../Variables.htm#Expressions">expression</a> (表达式)如果省略缺省情况下产生的最大的数是 2147483647 (这也是允许的最大整数 -- 但是浮点数没有限制)</td>
  29. </tr>
  30. <tr>
  31. <td>NewSeed</td>
  32. <td><p>此模式通过 <em>NewSeed</em> (可以是一个 <a href="../Variables.htm#Expressions">expression</a> (表达式)) 对随机数产生器重新定义种子这对随后产生的随机数都有影响<em>NewSeed</em> 应当是介于 0 4294967295 (0xFFFFFFFF)之间的整数重新定义种子能够提高所产生随机数的质量和安全性尤其当 <em>NewSeed</em> 是一个真正的随机数而不是像伪随机数一样质量欠佳时更是这样通常种子只需要重新定义一次即可</p>
  33. <p>如果脚本中从来没有重定义过种子种子使用一个 64 位值的低 32 位作为开始这个 64 位的值是从1601年1月1日开始100纳秒的数目这个低 32 位值从 0 变化至 4294967295其中100毫秒累计 ~7.2 分钟</p></td>
  34. </tr>
  35. </table>
  36. <h3>注意</h3>
  37. <p>此命令产生一个伪随机数即一个模拟真正随机数的数字但是它实际上是一个基于复杂方程式的使得决定或者猜测下一个数字极为困难的数字</p>
  38. <p>如果 <em>Min</em> 或者 <em>Max</em> 其中之一被设置为十进制浮点数最后的结果将是由 <a href="SetFormat.htm">SetFormat</a> 决定格式的浮点数否则结果将是一个整数</p>
  39. <p>结果是浮点数的局限1) 只有其中 32位用于产生变量2) 它偶尔也会比指定的 <em>Max</em> 略微大一点点(这是由浮点数内在的不精确性导致的)</p>
  40. <h3>相关命令</h3>
  41. <p><a href="SetFormat.htm">SetFormat</a></p>
  42. <h3>示例</h3>
  43. <pre class="NoIndent">Random, rand, 1, 10
  44. Random, rand, 0.0, 1.0</pre>
  45. <h3>关于原始资料的注释</h3>
  46. <P>此函数使用了 Mersenne Twister 随机数产生器MT19937, 原作者Takuji Nishimura , Matsumoto, Shawn Cokus, Matthe Bellew, Isaku Wada.</P>
  47. <P>Mersenne Twister 是一个用于产生随意数的算法它在考虑其他随机数产生器的基础上被设计出来它的循环周期2<SUP>19937</SUP>-1和它的等分布顺序623 dimensions(维度)都非常之大与此同时这个产生器非常快它避免了乘法和除法并且从缓存和管道中得益想了解更多请访问原作者的网站 www.math.keio.ac.jp/~matumoto/emt.html</P>
  48. <P><em>(译者注以下是关于算法的法律声明与使用限制一般不允许翻译但是这个没说以下就不翻译了不影响大家对此命令的使用^_^)</em></P>
  49. <P>Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.</P>
  50. <P>Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:</P>
  51. <OL>
  52. <LI>Redistributions of source code must retain the above copyright notice, this
  53. list of conditions and the following disclaimer.</LI>
  54. <LI>Redistributions in binary form must reproduce the above copyright notice,
  55. this list of conditions and the following disclaimer in the documentation
  56. and/or other materials provided with the distribution.</LI>
  57. <LI>The names of its contributors may not be used to endorse or promote products
  58. derived from this software without specific prior written permission.</LI>
  59. </OL>
  60. <P class="J">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  61. &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  62. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  64. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  66. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  67. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  68. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  69. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</P>
  70. <P>Do NOT use for CRYPTOGRAPHY without securely hashing several returned values
  71. together, otherwise the generator state can be learned after reading 624 consecutive
  72. values.</P>
  73. <P>When you use this, send an email to: matumoto@math.keio.ac.jp with an appropriate
  74. reference to your work. It would be nice to CC: rjwagner@writeme.com and Cokus@math.washington.edu
  75. when you write.</P>
  76. <P><I>This above has been already been done for AutoHotkey, but if you use the Random command in a publicly distributed application,
  77. consider sending an e-mail to the above people to thank them.</I></P>
  78. </body>
  79. </html>