VBMath.Randomize 方法

定义

初始化随机数生成器。Initializes the random-number generator.

重载

Randomize()

初始化随机数生成器。Initializes the random-number generator.

Randomize(Double)

初始化随机数生成器。Initializes the random-number generator.

Randomize()

初始化随机数生成器。Initializes the random-number generator.

public:
 static void Randomize();
public static void Randomize ();
static member Randomize : unit -> unit
Public Sub Randomize ()

示例

此示例使用 Randomize 语句初始化随机数生成器。This example uses the Randomize statement to initialize the random-number generator. 由于省略了 number 参数,因此 Randomize 使用函数的返回值 Timer 作为新的种子值。Because the number argument has been omitted, Randomize uses the return value from the Timer function as the new seed value.

' Initialize the random-number generator.
Randomize()
' Generate random value between 1 and 6.
Dim value As Integer = CInt(Int((6 * Rnd()) + 1))

注解

此方法的重载不 Randomize 采用种子值。This overload of the Randomize method does not take a seed value. 相反,系统计时器返回的值将用作新的种子值。Instead, the value returned by the system timer is used as the new seed value.

如果 Randomize 未使用,则 Rnd 没有) 参数的函数 (在第一次调用时将使用与种子相同的数字,并且随后使用最后生成的数字作为种子值。If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last-generated number as a seed value.

备注

若要重复随机数值序列,请 Rnd 在使用带有数值参数的前立即使用负参数调用 RandomizeTo repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument.

重要

由于 Random 语句和 Rnd 函数以种子值开始,并生成在有限范围内的数字,因此知道用于生成它们的算法的人员可能会预测结果。Because the Random statement and the Rnd function start with a seed value and generate numbers that fall within a finite range, the results may be predictable by someone who knows the algorithm used to generate them. 因此, Random Rnd 不应使用语句和函数来生成用于加密的随机数字。Consequently, the Random statement and the Rnd function should not be used to generate random numbers for use in cryptography. 有关详细信息,请参阅 RandomNumberGeneratorFor more information, see RandomNumberGenerator.

另请参阅

适用于

Randomize(Double)

初始化随机数生成器。Initializes the random-number generator.

public:
 static void Randomize(double Number);
public static void Randomize (double Number);
static member Randomize : double -> unit
Public Sub Randomize (Number As Double)

参数

Number
Double

可选。Optional. 一个 Object 或任何有效的数值表达式。An Object or any valid numeric expression.

示例

此示例使用 Randomize 语句初始化随机数生成器。This example uses the Randomize statement to initialize the random-number generator. 由于省略了 number 参数,因此 Randomize 使用函数的返回值 Timer 作为新的种子值。Because the number argument has been omitted, Randomize uses the return value from the Timer function as the new seed value.

' Initialize the random-number generator.
Randomize()
' Generate random value between 1 and 6.
Dim value As Integer = CInt(Int((6 * Rnd()) + 1))

注解

Randomize 使用 Number 初始化 Rnd 函数的随机数生成器,并为其提供新的种子值。Randomize uses Number to initialize the Rnd function's random-number generator, giving it a new seed value. 如果省略 Number ,系统计时器返回的值将用作新的种子值。If you omit Number, the value returned by the system timer is used as the new seed value.

如果 Randomize 未使用,则 Rnd 没有) 参数的函数 (在第一次调用时将使用与种子相同的数字,并且随后使用最后生成的数字作为种子值。If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last-generated number as a seed value.

备注

若要重复随机数值序列,请 Rnd 在使用带有数值参数的前立即使用负参数调用 RandomizeTo repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Randomize将与的值一起使用 Number 不会重复以前的序列。Using Randomize with the same value for Number does not repeat the previous sequence.

重要

由于 Random 语句和 Rnd 函数以种子值开始,并生成在有限范围内的数字,因此知道用于生成它们的算法的人员可能会预测结果。Because the Random statement and the Rnd function start with a seed value and generate numbers that fall within a finite range, the results may be predictable by someone who knows the algorithm used to generate them. 因此, Random Rnd 不应使用语句和函数来生成用于加密的随机数字。Consequently, the Random statement and the Rnd function should not be used to generate random numbers for use in cryptography. 有关详细信息,请参阅 RandomNumberGeneratorFor more information, see RandomNumberGenerator.

另请参阅

适用于