Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From my response to <a href="https://stackoverflow.com/questions/158716/how-do-you-efficiently-generate-a-list-of-k-non-repeating-integers-between-0-an#161552">another question</a>:</p> <blockquote> <p>It is actually possible to do this in space proportional to the number of elements selected, rather than the size of the set you're selecting from, regardless of what proportion of the total set you're selecting. You do this by generating a random permutation, then selecting from it like this:</p> <p>Pick a block cipher, such as <a href="http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm" rel="nofollow noreferrer">TEA</a> or XTEA. Use <a href="http://isthe.com/chongo/tech/comp/fnv/#xor-fold" rel="nofollow noreferrer">XOR folding</a> to reduce the block size to the smallest power of two larger than the set you're selecting from. Use the random seed as the key to the cipher. To generate an element n in the permutation, encrypt n with the cipher. If the output number is not in your set, encrypt that. Repeat until the number is inside the set. On average you will have to do less than two encryptions per generated number. This has the added benefit that if your seed is cryptographically secure, so is your entire permutation.</p> <p>I wrote about this in much more detail <a href="http://blog.notdot.net/archives/37-Damn-Cool-Algorithms,-Part-2-Secure-permutations-with-block-ciphers.html" rel="nofollow noreferrer">here</a>.</p> </blockquote> <p>Of course, there's no guarantee that every permutation can be generated (and depending on your block size and key size, that may not even be possible), but the permutations you can get are highly random (if they weren't, it wouldn't be a good cipher), and you can have as many of them as you want.</p>
    singulars
    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. 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