Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Reference Index > Managing User Privileges

Generating Random Numbers

Scroll Prev Top Next More

The basic procedure for generating a random number is to start with a "seed" number and then perform calculations on the "seed" number to generate the actual random numbers. Often the random number generated is used as the "seed" number for the next iteration. The thousandths part of the time format is used as the "seed" number in an R:BASE command file to generate random numbers. Various SuperMath functions and other arithmetic operations generate the random number. The calculations can be simple or complex; often the simpler calculations generate the more random number.

 

The following examples of calculations that generate a random number use the same "seed" number each time and also use the complete time value in the calculation. The time format is set so that it looks like a number.

 

SET TIME FORMAT HH:MM:SS.SSS

SET VAR vTime INTEGER = (INT(FORMAT(.#TIME,'HHMMSS')))

SET VAR vRandom1  = +

 (NINT(((IFRC(.#TIME))*100)/(NINT(CTXT((.vTime)))/10000)))

SET VAR vRandom2 = +

 (IFRC(.#TIME)+NINT(LOG(.vTime))+NINT(SQRT(.vTime)))

SET TIME FOR HH:MM:SS AP