iDevOS CALC "RND" Command
Generate a random number.
Description
CALC( y, a, "RND" ); // y = rand(a) = random number between 0 and a
This command returns the value y
which is a randomly generated number between 0
and a
.
Parameters
y
- Calculation result.
Parameter type: entity name of a numeric variable (egU8
,S32
,FLT3
etc). a
- Input value.
Parameter type: immediate number, or entity name of a numeric variable (egU8
,S32
,FLT3
etc). "RND"
- CALC command operator.
Parameter type: immediate string.
Examples
Example 1
VAR(d, 0.0, FLT4); CALC(d, 10, "RND"); // eg, d = 6.8936 CALC(d, 10, "RND"); // eg, d = 4.1276
Example 2
SETUP(RS2) { set="1152NY"; encode=sr; } VAR(d1, 0.0, FLT4); VAR(a1, 3141.5927, FLT4); VAR(d2, 0, S32); VAR(a2, 64, S32); VAR(d3, 0.0, FLT6); VAR(a3, 1.0, FLT4); LOOP(lp1, FOREVER) { CALC(d1, a1, "RND"); CALC(d2, a2, "RND"); CALC(d3, a3, "RND"); LOAD(RS2, d1, ", ", d2, ", ", d3, "\\0d\\0a"); WAIT(1000); } // An example output on RS2:3092.9024, 12, 0.900891 488.2170, 50, 0.022285 2385.6688, 52, 0.825658 23.1280, 59, 0.692254 422.8083, 62, 0.173811 553.7351, 59, 0.317508 3042.9832, 26, 0.570716 2385.2283, 26, 0.946548 1744.8570, 29, 0.113906 2302.0624, 51, 0.199057 2993.2816, 28, 0.352398 36.3087, 31, 0.509634 422.8089, 24, 0.123701