Since there is a limited number of numbers, you can do the following (assuming, for example, valid identifiers 0..99)
- When initializing for the first time, fill in an int array [100] with values 0..99
- In reset (and initialization) set int endoflist = 100
- When getting the identifier get index = rand ()% endoflist, decrement endoflist, swap array [index] with array [endoflist], return array [endoflist]
- When the endoflist reaches 0, set it back to 100 (there is no need to replenish the array, it still contains ID 0..99)
IMO this question is suitable for nothing but really junior posts.
source
share