Is there a way to use Rand to provide a number not in a linked list?

Basically I have a linked list already with some int numbers in it.
Is it possible for the Rand function to provide a number that is not already in that Linked list?
I have search pretty much everywhere and can't seem to find an answer.
Last edited on
You could generate a random number with std::rand() and check if it's in the list until you get a number that is not in the list.
meh
Last edited on
In this case you have very few possible random numbers. Only 100.

Instead of keeping track of all the numbers you have generated you can generate all the possible numbers from the start. Put all the numbers 0-99 in an array, std::vector or whatever. Use std::random_shuffle to put the numbers in random order. In getGuess() you just have to pick the next number and remove the number from the list so that it is not picked again later.
meh
Last edited on
meh
Last edited on
Topic archived. No new replies allowed.