Skip to main content
21 events
when toggle format what by license comment
Mar 31, 2014 at 4:48 history edited rm -rf CC BY-SA 3.0
deleted 1 characters in body; edited tags; edited title
Apr 11, 2012 at 18:41 comment added BlueRaja - Danny Pflughoeft @R.M. Right, so you create a list of indices, and treat each index like a card in a deck of cards. Then just shuffle the deck. Every time he wants n values from the list, return the top n cards. When the deck is empty, every index has been returned once. (It's much easier/more efficient to remember which numbers need to be returned, rather than which numbers have already been returned, but both have the same effect).
Apr 11, 2012 at 18:26 comment added rm -rf @BlueRaja: It's not that simple... most answers already use the random permutation of indices, but the OP wants only a certain number of those at a time, and wants the function to remember previously returned values till the list is empty
Apr 11, 2012 at 16:52 comment added BlueRaja - Danny Pflughoeft Sounds like what you really want is a random permutation of indices. Look up card-shuffling algorithms, they are extremely simple (or, knowing Mathematica, there's probably a function for that already :P)
Apr 11, 2012 at 16:34 comment added Eli Lansey @Lou I believe the general idea is that you can change your vote to the best (current) answer, as you see it.
Apr 11, 2012 at 16:23 comment added Lou @Eli Ok you're right. It seems that celtschk's answer would be the best solution. I'm not very sure about the ethics of choosing answers and switching one's opinion. It also seems a combined effort. Any guiding rules?
Apr 11, 2012 at 16:08 answer added rm -rf timeline score: 5
Apr 11, 2012 at 15:42 comment added Eli Lansey @Lou I suggest looking at celtschk's answer below. Also, it's generally advisable to wait a little before accepting an answer, as often a better answer comes a little late.
Apr 11, 2012 at 15:28 answer added celtschk timeline score: 11
Apr 11, 2012 at 15:13 answer added Pillsy timeline score: 8
Apr 11, 2012 at 15:12 history tweeted twitter.com/#!/StackMma/status/190094859674202112
Apr 11, 2012 at 15:02 vote accept Lou
Apr 11, 2012 at 14:51 history edited rcollyer CC BY-SA 3.0
formatted code; added a comma
Apr 11, 2012 at 14:30 comment added Lou I did but it doesn't seem to solve anything. RandomChoice is perfect already. I wanted to push the housekeeping to the function but it seemed complicated and perhaps to be avoided. Calling the function with any list until it's empty is essentialy the goal.
Apr 11, 2012 at 14:26 comment added Szabolcs What you describe reminds me a bit of closures (which I haven't used much personally). Please see if my answer is helpful.
Apr 11, 2012 at 14:25 answer added Szabolcs timeline score: 12
Apr 11, 2012 at 14:23 answer added Eli Lansey timeline score: 14
Apr 11, 2012 at 14:21 comment added Andy Ross Have you looked at RandomSample? if the critical component is sampling without replacement, that is a good place to start.
Apr 11, 2012 at 14:19 comment added Lou Yes I noticed that :) Using getRandomItem[{1,2,3}] as a downvalue didn't work either since it's up in the downvalue pattern matching stack.
Apr 11, 2012 at 14:15 comment added Lou Yes I realize that but using global variables is also a bit cumbersome (could add a counter field in the list e.g). So I just wondered if there's a neat way to do this. Perhaps there isn't..
Apr 11, 2012 at 14:03 history asked Lou CC BY-SA 3.0