Rand Function (Usual) | |
Return a random number between 0 and 1.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION Rand(
nSeed AS USUAL
) AS FLOAT
public static Float Rand(
Usual nSeed
)
Request Example
View SourceParameters
- nSeed
- Type: Usual
An optional start value.
This is the point at which the random number generator is initialized. Subsequent random numbers are then influenced by nSeed.
If you first call Rand() without nSeed, it starts as though 100001 were specified.
If you call the function with nSeed as 100001, it allows you to restart the generator.
Then, if you call the function several times without nSeed, it returns the "standard sequence" of numbers.
If nSeed is less than or equal to 0, the system time is brought into the process.
Return Value
Type:
FloatRemarks
Rand() allows you to generate pseudo-random numbers. Multiple calls to Rand() always return the same random number sequence, provided that they have the same start value (nSeed) on the first call and that any subsequent calls do not specify nSeed.
Examples
This example uses Rand() to generate the same sequence whenever it runs:
1
2? Rand(100001.0)
3? Rand()
4? Rand()
This example generates the same start value as the previous example but subsequent calls accept a seed value which is also influenced by the system time:
1? Rand(100001.0)
2? Rand(0.0)
3? Rand(0.0)
This example generates a sequence of random numbers and then reinitializes to the same seed to reproduce the same numbers:
1? Rand(100.0)
2? Rand()
3? Rand()
4? Rand(100.0)
5? Rand()
6? Rand()
This example multiplies the result by 100 to increase the range of returned values:
See Also