Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unless you have good reasons to, you don't want to reinvent pseudo random generation. It is quite possible to get something wrong. I'd suggest starting with an array with A[i]=i</p> <p>then do this: </p> <pre><code>for (i=0; i&lt; n; i++) { j = random_number_between(i,n-1); swap(A[i],A[j]); } </code></pre> <p><strong>Edit</strong> This is in response to the comments below:</p> <p>How random do you want the sequence to be. Note that the inherent information in a randomly chosen permutation is log(n!) which is somewhere close to n/e bits. So you do need that many random bits to be generated. Now since you want these many random bits stored anywhere I think (more like a gut feeling than a mathematical proof) it would be hard to do a truly random permutation without that much storage). </p> <p>But if you just want a sequence that is not easy to reverse engineer you could just concatenate a number of 1:1 functions one after the other. Two things come to mind: - keep a counter i for the sequence that goes from 0 through N-1.</p> <ul> <li><p>do log_2(N/2) bit flips on i where bits to flip are chosen at random when when you are starting the sequence.</p></li> <li><p>generate a random permutation over log_2(N) bits at the beginning of sequence using the above method and then swap the bits in the result above.</p></li> <li><p>Find a random number r1 that is a relative prime to n at and another random number r2 between 0 and n-1. Your i-th number is = r2^r % n.</p></li> </ul> <p>Some combination of these should give you a hard to reverse engineer sequence. The key is that the more random bits you infuse the harder it is to reverse engineer.</p> <p>One thing that comes to mind is that if your range is 0..N-1, just find a large number P that is a relative prime to N and choose another random number </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.
 

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