11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsParametersrangeA nonzero positive integer used to calculate the random number. The number returned isbetween zero and the value of range-1. It can be a nonzero positive integer value, the nameof an integer variable, or any valid <strong>Caché</strong> <strong>ObjectScript</strong> expression that evaluates to a nonzeropositive integer.ExamplesThe following example returns a random number from 0 through 24 (inclusive).WRITE $RANDOM(25)To return a random number with a decimal portion, you can use the concatenation operator(_) or the addition operator (+), as shown in the following example:SET x=$RANDOM(10)_$RANDOM(10)/10WRITE !,xSET y=$RANDOM(10)+($RANDOM(10)/10)WRITE !,yThis program returns numbers with one decimal position, ranging between .0 and 9.9(inclusive). Using either operator, <strong>Caché</strong> deletes any leading and trailing zeros (and the decimalpoint, if the decimal portion is zero). However, if both $RANDOM functions returnzero (0 and .0), <strong>Caché</strong> returns a zero (0).The following example simulates the roll of two dice.DiceWRITE !,"Do you want to roll the dice?"WRITE !, "Press to exit"READ !,"Roll Dice",AQUIT:A=""WRITE !,$RANDOM(6)+1,"+",$RANDOM(6)+1GOTO Dice294 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!