This site works best with JavaScript enabled!

Description: Random Generator - YES / NO

Random Generator Yes No

In this article the algorithm of the "YES / NO" generator is described. The random generator randomly generates the answer Yes or No. If you are unsure and need an oracle, then this site will help you. With the cryptographically safe random generator you do not have to make any decisions by yourself.


What is randomness?

Randomness is an event whose state cannot be clearly predicted causally. This means that the result of a random generator may not be predictable or computable. This, however, contradicts the laws of each computer. In other words, a computer can not produce absolutely random numbers without additional peripherals. In this case we call it pseudo-random numbers. In general, you can philosophize about at which point you can actually speak about randomness in practise.

How are the random values generated?

Theoretically, several different methods are used in this generator to generate pseudo-random values. For the actual "yes/no" answer, a PHP function for cryptographically secure pseudo random numbers is used.

Random generators for binary string

The purpose of the binary string is on the one hand the better optics and on the other hand the fact that the user can ensure that a new random value has actually been generated.

The server-side generated binary string is only visible when JavaScript is disabled. The PHP functions mt_rand() and decbin() are used for this purpose. The first function generates the actually random number and the second one converts the decimal number into a binary number. In principle, the following algorithm is used:

1
2
3
4
5
$random_string = "";
while (strlen($random_string) < PREFERRED_LENGTH)
{
   $random_string .= decbin(mt_rand(NUMBER1, NUMBER2));
}

In an previous version of this random generator, the binary string was also generated on client-side with JavaScript enabled using a modified Fisher-Yates shuffle:

1
2
3
4
5
6
7
8
9
10
var string = "010010101010010101010101010110101010101001011010";
var n = string.length;

for (var i = n - 1; i > 0; i--)
{
   var j = Math.floor(Math.random() * (i + 1));
   var tmp = string[i];
   string[i] = string[j];
   string[j] = tmp;
}

Random generator for random answer

The previous random number generators produce relatively good random numbers, which, however, can further be improved. The random answer is therefore always generated on server-side with the PHP function random_int(), which generates cryptographically secure pseudo-random numbers:

1
2
3
4
5
6
7
8
if ((bool)random_int(0, 1))
{
   $random_answer = "YES";
}
else
{
   $random_answer = "NO";
}
TO THE RANDOM GENERATOR
Share this page
Posted on 20.11.2016 | Last modified on 07.04.2021