Solution to 014e: Random numbers
See code at solutions/code/tutorialquestions/question014e
The sample source code uses an array of booleans,
found
, to determine whether each number in the given range has been found.
A while
loop is used to continually generate random numbers in the range,
on each iteration setting found[num]
to true, where num
is the generated number.
The program counts how many unique numbers have been generated, and the loop exits when this
number reaches the maximum permissible number. An alternative would be to exit the loop
when found
becomes uniformly false, though this would be considerably
less efficient.