KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method: Wrapper for the Random command
PRODUCT: 4D | VERSION: 12.4 | PLATFORM: Mac & Win
Published On: August 13, 2012

Here is a wrapper for the Random command to make it much easier to specify a the parameters for your randomization:

// return a random number in $0 that is between $1 and $2
// or any random in $0 if(Count parameters#2)
C_LONGINT($0;$1;$2)
If (Count parameters=2)
   $vStart:=$1
   $vEnd:=$2
   $0:=(Random%($vEnd-$vStart+1)+$vStart)
Else
   $0:=Random
End if


If the above method is saved as UTIL_Random it could be used like this:

$tempV:=UTIL_Random (1;$height) // random number between 1 and height