That's not a good solution, even though it'll work in this case (since you only have 50). With larger sizes you'll endlessly hang the cpu as it regenerates and checks the numbers. What you need to do is store all your numbers in a list, (1,2 ... 500) pick a random index from the list, and return the number at that index. Then remove the number at that index from the list and repeat. This way the operation completes in a known time.
+1 to this method. It is nice and simple.
If you aren't comfortable working with arrays, you could even do this with sprites to which you have assigned a number for the instance variable:
1. Use "pick random instance", store the number assigned to that instance in an array, then delete that sprite instance.
2. Repeat until all of the instances have been destroyed.
I recommend learning how to do this with arrays though, as creating sprites for the sole purpose of destroying them is kind of wasteful.