Note that another cool trick for this is to create a table in a database that has a two columns one for used and one for the value, like so:
nums:
num | used
0 | t
1 | f
2 | f
3 | f
4 | f
5 | f
6 | t
7 | t
8 | f
9 | t
and so on.
then you can detect if you need to shuffle because there aren't enough values left:
select count(*) from nums where used is true;
if that count is < a certain threshold, then you can "reshuffle" by just
update nums set used = FALSE;
then to get a random row, you just use
select num from nums where used is false order by random();
Then, you use
update nums set used = true where num='num';
to mark the row used.