Random

의사-무작위 수를 생성합니다.

Random, OutputVar , Min, Max
Random, , NewSeed

매개변수

OutputVar

The name of the output variable in which to store the result. The format of stored floating point numbers is determined by SetFormat if its slow mode is used; otherwise SetFormat only affects formatting when the number is converted to a string.

Min
생성될 가장 작은 수. 음수나 부동 소수점수 또는 표현식 가능. 생략하면, 가장 작은 값은 0입니다. 정수에 대하여 허용되는 가장 낮은 값은 -2147483648 for integers이지만, 부동 소수점 수는 제한이 없습니다.
Max

생성될 가장 큰 수, 음수나 부동 소수점 수 또는 표현식 가능. 생략하면, 가장 큰 수는 정수에 대하여 2147483647입니다 (그러나 부동 소수점 수는 제한이 없습니다).

NewSeed

이 모드는 무작위 수 발생자에 NewSeed로 다시 씨앗을 먹입니다 (표현식 가능). 이것은 이어 발생되는 모든 무작위 수에 영향을 미칩니다. NewSeed는 0부터 4294967295 (0xFFFFFFFF) 사이의 정수여야 합니다. 다시 씨앗 먹기기는 발생된 무작위 수의 품질/보안성을 향상시킬 수 있습니다. 특히 NewSeed가 품질이 떨어지는 의사-무작위 수가 아니라 진짜 무작위수이면 더 좋습니다. 일반적으로, 씨앗 다시 먹이기는 한 번 이상 할 필요가 없습니다.

스크립트에서 다시 씨앗 먹이기가 사용되지 않았다면, 씨앗은 64-비트 값의 아래쪽 32-비트로 시작합니다. 이 값은 1601년 1월 1일 이후로 100-나노초 간격으로 나눈 개수입니다. 이 값은 ~7.2 분마다 0부터 4294967295 사이를 왔다 갔다 합니다.

논평

이 명령어는 의사-무작위 수를 산출합니다. 이 수는 진짜 무작위 수를 흉내 내지만 실제로는 다음 숫자가 무엇인지 추측/결정하기가 지극히 어려운 복잡한 공식에 기반한 숫자일 뿐입니다.

지정된 범위 안의 숫자는 모두 대략 비슷한 빈도로 발생됩니다 (그렇지만, 아래의 "알려진 한계"를 참조하십시오).

Min 또는 Max에 소수 점이 들어 있다면, 최종 결과는 부동 소수점 수가 됩니다. 형식은 SetFormat에 의하여 결정됩니다. 그렇지 않으면, 그 결과는 정수입니다.

알려진 한계: 부동 소수점 수에 대하여: 1) 특정 범위에 대하여 대략 4,294,967,296개의 구분된 숫자만 발생시킬 수 있습니다. 그래서 범위 안의 다른 모든 숫자들은 절대로 발생되지 않습니다; 2) 가끔 결과가 지정된 최대값(Max)보다 더 큰 경우가 있습니다. (이것은 부분적으로 부동 소수점 수로부터 정밀도를 물려 받았기 때문입니다).

Format(), SetFormat

예제

Generates a random integer in the range 1 to 10 and stores it in rand.

Random, rand, 1, 10

Generates a random floating point number in the range 0.0 to 1.0 and stores it in rand.

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.sci.hiroshima-u.ac.jp/~m-mat/MT/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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. 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.
  3. 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: m-mat@math.sci.hiroshima-u.ac.jp with an appropriate reference to your work.

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 person to thank him.