Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 722 Bytes

014e.md

File metadata and controls

16 lines (12 loc) · 722 Bytes

Back to questions

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.