/* Program name: RandNums */ /* */ /* Creates a given number of unique random numbers between 1 and a */ /* limit, and outputs those numbers to a custom CLI window. */ /* */ /* To run this program, type: */ /* rx RandNums */ /* */ OPTIONS PROMPT 'Input Maximum number? 10-999: ' /* Prompt for input. */ PULL high /* Get the highest number to generate. */ OPTIONS PROMPT 'Input How Many numbers? 5-498: ' /* Prompt for input. */ PULL howmany /* Get the number of numbers to make. */ IF high <10 THEN high = 10 /* Make the high number at least 10, */ IF high >999 THEN high = 999 /* but no more than 999. */ IF (howmany<5) | (howmany>TRUNC(high/2)) THEN howmany=TRUNC(high/2) /* Set a reasonable value for howmany. */ SAY 'Generating' howmany 'unique random numbers from 1 to' high OPEN('Random','CON:160/50/345/100/Random') /* Open custom CLI. */ q. = 0 /* Set all the test values to zero. */ CALL TIME 'R' /* Reset system timer. */ DO howmany /* Do until howmany numbers are made. */ DO UNTIL q.z ~= z /* Test for uniqueness. */ z=RANDOM(1,high,TIME('s')) /* Generate a random number in range. */ END /* End inner DO loop. */ q.z = z /* Set the value to say it's used. */ CALL WRITECH('Random',RIGHT(z,3,'0') '') /* Output to the window. */ END /* End the outer DO loop. */ t = TIME('E') /* Get elapsed time. */ SAY 'Elapsed Time:' t 'Seconds' /* Report elapsed time. */ CALL CLOSE('Random') /* Close the output window. */