Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Neither is 'more random'.</p> <p><code>rand()</code> generates a predictable set of numbers based on a psuedo-random seed (usually based on the current time, which is always changing). Multiplying two consecutive numbers in the sequence generates a different, but equally predictable, sequence of numbers.</p> <p>Addressing whether this will reduce collisions, the answer is no. It will actually increase collisions due to the effect of multiplying two numbers where <code>0 &lt; n &lt; 1</code>. The result will be a smaller fraction, causing a bias in the result towards the lower end of the spectrum.</p> <p>Some further explanations. In the following, 'unpredictable' and 'random' refer to the ability of someone to guess what the next number will be based on previous numbers, ie. an oracle.</p> <p>Given seed <code>x</code> which generates the following list of values: </p> <pre><code>0.3, 0.6, 0.2, 0.4, 0.8, 0.1, 0.7, 0.3, ... </code></pre> <p><code>rand()</code> will generate the above list, and <code>rand() * rand()</code> will generate:</p> <pre><code>0.18, 0.08, 0.08, 0.21, ... </code></pre> <p>Both methods will always produce the same list of numbers for the same seed, and hence are equally predictable by an oracle. But if you look at the the results for multiplying the two calls, you'll see they are all under <code>0.3</code> despite a decent distribution in the original sequence. The numbers are biased because of the effect of multiplying two fractions. The resulting number is always smaller, therefore much more likely to be a collision despite still being just as unpredictable.</p>
 

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