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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.