Very often you find that you need to generate an array of integers where each integer is unique. The program below contains two functions that do that in different ways. One uses a boolean array to keep track of the numbers that have been generated. If a number has already been generated, more numbers are generated until you get one that hasn't been generated yet, thus guaranteeing no repeats.
The other method is more complex and involves a tree. The rand ()
function is called fewer times with this method. This method tends to be faster when generating large arrays of numbers.