diff --git a/source/text/sbasic/shared/03080301.xhp b/source/text/sbasic/shared/03080301.xhp index 51fb84f207..34c4756bf3 100644 --- a/source/text/sbasic/shared/03080301.xhp +++ b/source/text/sbasic/shared/03080301.xhp @@ -34,28 +34,27 @@ -Randomize Statement [Runtime] -Initializes the random-number generator. +Randomize Statement [Runtime] +Initializes the random-number generator used by the Rnd function. Syntax: - Randomize [Number] - Parameters: - Number: Any integer value that initializes the random-number generator. + 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. Example: - Sub ExampleRandomize -Dim iVar As Integer, sText As String +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) ) ' Range from 0 To 9 + iVar = Int(10 * Rnd) ' Range from 0 to 9 iSpectral(iVar) = iSpectral(iVar) +1 Next iCount sText = " | " @@ -64,7 +63,10 @@ Next iCount MsgBox sText,0,"Spectral Distribution" End Sub - + +
+ +
\ No newline at end of file diff --git a/source/text/sbasic/shared/03080302.xhp b/source/text/sbasic/shared/03080302.xhp index ef378256e3..7ba71b641b 100644 --- a/source/text/sbasic/shared/03080302.xhp +++ b/source/text/sbasic/shared/03080302.xhp @@ -34,27 +34,23 @@ -Rnd Function [Runtime] +Rnd Function [Runtime] Returns a random number between 0 and 1. Syntax: - Rnd [(Expression)] - Return value: Double Parameters: - Expression: Any numeric expression. - Omitted: Returns the next random number in the sequence. -The Rnd function only returns values ranging from 0 to 1. To generate random integers in a given range, use the formula in the following example: + Expression: Has no effect, is ignored if provided. +The Rnd function returns decimal fractions ranging from 0 (included) to 1 (excluded) according to a uniform distribution. It uses the Mersenne Twister 19937 random-number generator. To generate random integers in a given range, use a formula like in the example below. A Randomize statement with a defined seed value can be used beforehand, if a predictable sequence of numbers is desired. Example: - Sub ExampleRandomSelect Dim iVar As Integer iVar = Int((15 * Rnd) -2) @@ -69,7 +65,10 @@ Print "Outside range 1 to 10" End Select End Sub - + +
+ +
\ No newline at end of file