Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just remembered a similar problem from a class I took years ago; that is, iterating (relatively) randomly through a set (completely exhausting it) given extremely tight memory constraints. If I'm remembering this correctly, our solution algorithm was something like this:</p> <ol> <li>Define the range to be from 0 to some number <em><code>N</code></em></li> <li>Generate a random starting point <em><code>x[0]</code></em> inside <em><code>N</code></em></li> <li>Generate an iterator <em><code>Q</code></em> less than <code>N</code></li> <li>Generate successive points <em><code>x[n]</code></em> by adding <code>Q</code> to the previous point and wrapping around if needed. That is, <code>x[n+1] = (x[n] + Q) % N</code></li> <li>Repeat until you generate a new point equal to the starting point.</li> </ol> <p>The trick is to find an iterator that will let you traverse the entire range without generating the same value twice. If I'm remembering correctly, any relatively prime <code>N</code> and <code>Q</code> will work (the closer the number to the bounds of the range the less 'random' the input). In that case, a prime number that is not a factor of <code>N</code> should work. You can also swap bytes/nibbles in the resulting number to change the pattern with which the generated points "jump around" in <code>N</code>.</p> <p>This algorithm only requires the starting point (<code>x[0]</code>), the current point (<code>x[n]</code>), the iterator value (<code>Q</code>), and the range limit (<code>N</code>) to be stored.</p> <p>Perhaps someone else remembers this algorithm and can verify if I'm remembering it correctly?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload