Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have played around and I write <a href="http://gist.github.com/105929" rel="nofollow noreferrer">"testing environment"</a> for this Rand(7) algorithm. For example if you want to try what distribution gives your algorithm or how much iterations takes to generate all distinct random values (for Rand(7) 1-7), you <a href="http://gist.github.com/105929" rel="nofollow noreferrer">can use it</a>.</p> <p>My core algorithm is this:</p> <pre><code>return (Rand5() + Rand5()) % 7 + 1; </code></pre> <p>Well is no less uniformly distributed then Adam Rosenfield's one. (<a href="http://gist.github.com/105929" rel="nofollow noreferrer">which I included in my snippet code</a>)</p> <pre><code>private static int Rand7WithRand5() { //PUT YOU FAVOURITE ALGORITHM HERE// //1. Stackoverflow winner int i; do { i = 5 * (Rand5() - 1) + Rand5(); // i is now uniformly random between 1 and 25 } while (i &gt; 21); // i is now uniformly random between 1 and 21 return i % 7 + 1; //My 2 cents //return (Rand5() + Rand5()) % 7 + 1; } </code></pre> <p>This "testing environment" can take any Rand(n) algorithm and test and evaluate it (distribution and speed). Just put your code into the "Rand7WithRand5" method and run the snippet.</p> <p>Few observations:</p> <ul> <li>Adam Rosenfield's algorithm is no better distributed then, for example, mine. Anyway, both algorithms distribution is horrible.</li> <li>Native Rand7 (<code>random.Next(1, 8)</code>) is completed as it generated all members in given interval in around 200+ iterations, Rand7WithRand5 algorithms take order of 10k (around 30-70k)</li> <li>Real challenge is not to write a method to generate Rand(7) from Rand(5), but it generate values more or less uniformly distributed.</li> </ul>
    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. 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