Q. TSE: Documentation: Random()
(see also the latest TSE '
read.me' file)
Syntax: INTEGER Random([integer lo[, integer hi]])
1. If hi > lo, and lo >= 0:
Returns an integer pseudo random number in the range lo .. hi,
inclusive.
E.g. if lo = 1 and hi = 100 returns an integer pseudo number in the range 1 .. 100
(inclusive)
2. -If lo > 0: (and hi is 0 or < lo):
Returns an integer pseudo random number in the range 0 .. lo - 1.
E.g. if lo = 10 and hi = 0 returns an integer pseudo number in the range 0 .. 9
(inclusive)
E.g. if lo = 10 and hi = 9 returns an integer pseudo number in the range 0 .. 9
(inclusive)
3. -Otherwise, it returns an integer pseudo random number in the range
0..MAXINT.
In a 32-bits TSE that is an integer random value between 0 and 2^31 - 1 or thus
2147483647
Returns: An integer random value between 0 and MAXINT
Note: The generator is based on code contributed by
David Goodenough.
Thanks David!
SeedRand([integer seed])
------------------------
if seed > 0, seed is used as the random number generator
seed. Otherwise, seed is set to a value based on the system
clock.
E.g. SeedRand( 10 ) // here 10 is used as the random number generator seed
E.g. SeedRand() // here the system clock is used as the random number generator seed
1. -Under Windows, the Windows GetTickCount() function is
called, which retrieves the number of milliseconds that
have elapsed since the system was started, up to 49.7
days.
2. Under Linux:
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
The tv argument is a struct timeval (as specified in
<sys/time.h>):
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
and gives the number of seconds and microseconds since the
Epoch.
Examples:
--- cut here: begin --------------------------------------------------
PROC Main()
//
INTEGER randomValueI = 0
INTEGER minI = 0
INTEGER maxI = 0
//
// If lo = 0 (and hi > lo): Returns an integer pseudo random number in the range lo .. hi,
minI = 0
maxI = 100
randomValueI = Random( minI, maxI )
Warn( "Random integer value generated between: " + Str( minI ) + " and " + Str( maxI ) + " = " + Str( randomValueI ) ) // gives e.g. 70
//
// If lo > 0 (and hi > lo): Returns an integer pseudo random number in the range lo .. hi,
minI = 1
maxI = 100
randomValueI = Random( minI, maxI )
Warn( "Random integer value generated between: " + Str( minI ) + " and " + Str( maxI ) + " = " + Str( randomValueI ) ) // gives e.g. 70
//
// if lo > 0 (and hi is 0): Returns an integer pseudo random number in the range 0 .. lo - 1.
minI = 8
maxI = 0
randomValueI = Random( minI, maxI )
Warn( "Random integer value generated between: " + Str( maxI ) + " and " + Str( minI - 1 ) + " = " + Str( randomValueI ) ) // gives e.g. 6
//
// if lo > 0 (and hi is < lo): Returns an integer pseudo random number in the range 0 .. lo - 1.
minI = 8
maxI = 7
randomValueI = Random( minI, maxI )
Warn( "Random integer value generated between: " + Str( maxI ) + " and " + Str( minI - 1 ) + " = " + Str( randomValueI ) ) // gives e.g. 5
//
END
--- cut here: end ----------------------------------------------------