Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference > Siebel VB Language Reference >
Rnd Function
This standard VB function returns a single-precision random number between 0 and 1.
Syntax
Rnd[(number)]
Argument Description number A numeric expression indicating how the random number is to be generated
Returns
A single-precision pseudo-random number between 0 and 1.
Usage
If number is less than zero, the specified number is used as the seed for a pseudo-random number, which is generated every time the Rnd function is executed. If number is greater than zero, or is omitted, Rnd generates a sequence of pseudo-random numbers, in which each execution of the Rnd function uses the next number in the sequence. If number is equal to zero, Rnd uses the number most recently generated.
The same sequence of random numbers is generated whenever Rnd is run, unless the random number generator is re-initialized by the Randomize statement.
Example
This example generates a random string of characters within a range. The Rnd function is used to set the range between lowercase a and z. The second For...Next loop is to slow down processing in the first For...Next loop so that Randomize can be seeded with a new value each time from the Timer function.
Sub Button_Click
Dim x as Integer
Dim y
Dim str1 as String
Dim str2 as String
Dim letter as String
Dim randomvalue
Dim upper, lower
Dim msgtext
upper = Asc("z")
lower = Asc("a")
newline = Chr(10)
For x = 1 to 26
Randomize
randomvalue = Int(((upper - (lower + 1)) * Rnd) + lower)
letter = Chr(randomvalue)
str1 = str1 & letter
For y = 1 to 1500
Next y
Next x
msgtext = str1
End SubSee Also
Exp Function
Fix Function
Int Function
Log Function
Randomize Statement
Sgn Function
Sqr Function
Bookshelf Home | Contents | Index | Search | PDF |
Siebel VB Language Reference Published: 18 June 2003 |