SetRandomSeed()

Summary

Seeds the RandomNumber() function.

Syntax

SetRandomSeed(integer seed_value)

Argument Contents
seed_value A seed for theRandomNumber()function

Notes

  • You can call SetRandomSeed() with a particular seed value, which will always create the same sequence of random numbers. This is useful when testing a procedure, so that results will be comparable.

  • To get different results every time your macro is run, you need to feed a "random" seed to SetRandomSeed(). The best way to generate good seed values is by using a time and/or date function, such as GetDateAndTime().

  • When the platform is initialized there is a call to SetRandomSeed() with a "random" seed based on the current time, so you do not need to call SetRandomSeed() to ensure randomness.

Example

// Use current time in seconds past midnight as the random seed
t = GetDateAndTime() // For example, "Wed Oct 19 10:48:42 1994"
x = ParseString(t, " ") // {"Wed", "Oct", "19", "10:48:42", "1994"}
y = ParseString(x[4], ":") // hh:mm:ss -> {"hh","mm","ss"}
Seconds = s2i(y[1])*3600+s2i(y[2])*60+s2i(y[3]) // Seconds past midnight
SetRandomSeed(Seconds)

See Also

Function Summary
RandomNumber() Generates a random number between 0.0 and 1.0
RandSamples() Return an array of random samples of the given type of random distribution and parameters defined in the options array
GetDateAndTime() Determines the current date and time according to the system clock.