This may be a simplistic way of looking at it, but when I read your post, my first thought was to keep track of last "hour" the item was "returned", although in this case "hour" would be calculated as int( ( time + 300 ) / 3600 ) % 24. This would mean that anything from 3100 to 3599 (:55 to :59:59) as well as anything from 0 to 3099 (:00:00 to :54:59) will evaluate to the same hour. I had considered a while() loop, getting a random index and checking if the return "hour" and the current hour (UTC) matched.
As I typed the paragraph above, however, I realized there was possibly a simpler way: maintain a pointer or index of the number of un-returned items this hour, pick your next item at random between 0 and this index, then swap the one picked and the value of the index, and decrement the index. So, for example, you have 10 items (0..9). Pick one at random (8), return it, then swap it and item 9, and decrement your max to 9. Pick another at random from 0..8, and so forth.
I have no illusions that the two ideas above are the best, but they are ideas, and I hope they prove helpful.
In reply to Re: Embargo algorithm
by atcroft
in thread Embargo algorithm
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |