I'm trying to create a function that randomly returns a value from a list but remembers the values that have been given before. At the end when the list is empty it should return an empty list. Basically like emptying a bucket full of eggs one at a time.
Suppose I have two lists:
data1 = Range[10];
data2 = Range[20];
Asume function
getRandomItem[l_List]
I tried playing with downvalues but that doesn't work.
Calling getRandomItem[data1] two times would give (e.g)
{1} and {3}
Calling getRandomItem[data2] two times would give (e.g)
{15} and {20}
At the end as stated before when all items are chosen both
getRandomItem[data1] and getRandomItem[data2]
should return {}.
I would like to do that without declaring data1 and data2 as global variables nor do I which to change/alter them.
So, basically I presume the function itself should remember which data has been given to it and where it had left the previous time.


RandomSample? if the critical component is sampling without replacement, that is a good place to start. – Andy Ross Apr 11 '12 at 14:21