I was just browsing some great posts here and there online and just started wondering if there is an algorithm that generates random positive numbers, ranging from 0-infinite.
I've seen the Fisher-Yates algorithm that creates an array of numbers in order and shuffles within O(n).
Just out of curiosity, what would be the time complexity of the following pseudocode?
ranNumGenerator(int n) {
repeat until you get n random numbers {
create randNumArray
generate a random positive number (range 0-largest integer available)
if !(randNumArray contains the generated number)
add to randNumArray
}
}
I can't seem to figure out what would be its time complexity, neither how I would make it better and more efficient.