Randomize Statement

Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅Ρ‚ Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ случайных чисСл, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹ΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠ΅ΠΉ Rnd.

Бинтаксис

Randomize [Число]

ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹:

Number: Any integer value. Used as seed to initialize the random-number generator. Equal seeds result in equal random-number sequences by the Rnd function. If the parameter is omitted, the Randomize statement will be ignored.

Π—Π½Π°Ρ‡ΠΎΠΊ примСчания

Unless a predictable sequence of numbers is desired, there is no need to use the Randomize statement, as the random-number generator will be initialized automatically at first use – it will be seeded using a system-provided random-number generator that produces uniformly-distributed, non-deterministic random numbers. If no such generator is available on the system, the system time will be used as seed.


The Randomize statement affects BASIC's Rnd function only. Other random-number generators (for example the Calc's RAND() function, etc.) are not affected by it.

Error codes:

5 ΠΠ΅ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ Π²Ρ‹Π·ΠΎΠ² ΠΏΡ€ΠΎΡ†Π΅Π΄ΡƒΡ€Ρ‹

ΠŸΡ€ΠΈΠΌΠ΅Ρ€:

Sub ExampleRandomize

Dim iCount As Integer, iVar As Integer, sText As String

Dim iSpectral(10) As Integer

    Randomize 2^14-1

    For iCount = 1 To 1000

    iVar = Int(10 * Rnd) ' Π”ΠΈΠ°ΠΏΠ°Π·ΠΎΠ½ ΠΎΡ‚ 0 Π΄ΠΎ 9

        iSpectral(iVar) = iSpectral(iVar) +1

    Next iCount

    sText = " | "

    For iCount = 0 To 9

        sText = sText & iSpectral(iCount) & " | "

    Next iCount

    MsgBox sText,0,"Π‘ΠΏΠ΅ΠΊΡ‚Ρ€Π°Π»ΡŒΠ½ΠΎΠ΅ распрСдСлСниС"

End Sub