64-Bit True Random Number Generator: A Classical TRNG Algorithm With Quantum-Level Entropy From CPU Oscillations and Temporal Precision Theory

Eightomic developed a cryptographically-secure, 64-bit, truly-random integer generator with a hybrid TRNG system that guarantees non-deterministic randomness captured from quantum-level entropy.

Library

Source

<?php class EightomicRandomize { public $output_numbers_count = 1; public $output_number_digits_minimum_count = 1; public $output_number_letter_case = "lower"; public $output_number_prefix = ""; public $output_number_radix = 10; public $output_number_range_maximum = "9223372036854775807"; public $output_number_range_minimum = "-9223372036854775808"; public $output_number_signedness = "signed"; public $output_number_suffix = ""; function process() { $this->output_numbers = false; if (ctype_digit(strval($this->output_numbers_count)) == false) { return 1; } if (ctype_digit(strval($this->output_number_digits_minimum_count)) == false) { return 2; } if ( $this->output_number_letter_case != "lower" && $this->output_number_letter_case != "upper" ) { return 3; } if (is_string($this->output_number_prefix) == false) { return 4; } if (ctype_digit(strval($this->output_number_radix)) == true) { if ($this->output_number_radix >= 2) { if ($this->output_number_radix > 32) { return 7; } } else { return 6; } } else { return 5; } if ( $this->output_number_signedness != "signed" && $this->output_number_signedness != "unsigned" ) { return 8; } if ($this->output_number_signedness == "signed") { if ($this->output_number_range_maximum >= "-9223372036854775807") { if ($this->output_number_range_maximum > "9223372036854775807") { return 10; } } else { return 9; } } else { if ($this->output_number_range_maximum >= "1") { if ($this->output_number_range_maximum > "18446744073709551615") { return 12; } } else { return 11; } } if ($this->output_number_signedness == "signed") { if ($this->output_number_range_minimum >= "-9223372036854775808") { if ($this->output_number_range_minimum > "9223372036854775806") { return 14; } } else { return 13; } } else { if ($this->output_number_range_minimum >= "0") { if ($this->output_number_range_minimum > "18446744073709551614") { return 16; } } else { return 15; } } if ($this->output_number_range_maximum <= $this->output_number_range_minimum) { return 17; } if (is_string($this->output_number_suffix) == false) { return 18; } $this->output_numbers = new SplFixedArray($this->output_numbers_count); $output_number = 1; $entropy = 1111111111; $oscillation = 1111111111; while ($output_number > 0) { $output_number <<= 1; $oscillation *= ( (($entropy / 111111) % 111) + (($entropy + $oscillation) % 111) ); $oscillation /= ($entropy - $oscillation) | 1; $oscillation = (($entropy + $oscillation) % 65535) + 111111; $entropy = hrtime(true); if ($entropy !== false) { $output_number |= $entropy & 1; } else { $output_number = -1; } } if ($entropy === false) { return 19; } $oscillation *= ( (($entropy / 111111) % 111) + (($entropy + $oscillation) % 111) ); $oscillation /= ($entropy - $oscillation) | 1; $oscillation = (($entropy + $oscillation) % 65535) + 111111; $entropy = hrtime(true); if ($entropy === false) { return 19; } $output_number <<= 1; $this->output_numbers[0] = $output_number | ($entropy & 1); if ($this->output_numbers_count > 1) { $i = 1; while ($i != $this->output_numbers_count) { $output_number = 1; while ($output_number > 0) { $output_number <<= 1; $oscillation *= ( (($entropy / 111111) % 111) + (($entropy + $oscillation) % 111) ); $oscillation /= ($entropy - $oscillation) | 1; $oscillation = (($entropy + $oscillation) % 65535) + 111111; $entropy = hrtime(true); if ($entropy !== false) { $output_number |= $entropy & 1; } else { $output_number = -1; } } if ($entropy === false) { return 19; } $oscillation *= ( (($entropy / 111111) % 111) + (($entropy + $oscillation) % 111) ); $oscillation /= ($entropy - $oscillation) | 1; $oscillation = (($entropy + $oscillation) % 65535) + 111111; $entropy = hrtime(true); if ($entropy === false) { return 19; } $output_number <<= 1; $this->output_numbers[$i] = $output_number | ($entropy & 1); $i++; } } $output_number_range_delta = bcsub( bcadd($this->output_number_range_maximum, "1"), $this->output_number_range_minimum ); $i = 1; if ( $this->output_number_signedness == "signed" && $this->output_number_range_minimum < 0 ) { if ($this->output_numbers[0] < 0) { $output_number = bcadd( strval(~$this->output_numbers[0]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[0]); } if ($this->output_number_radix == 10) { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); if ($output_number[0] == "-") { $this->output_numbers[0] = "-" . $this->output_number_prefix; $this->output_numbers[0] .= str_pad( substr($output_number, 1), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } else { $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $this->output_number_range_delta), $this->output_number_range_minimum ); if ($output_number[0] == "-") { $this->output_numbers[$i] = "-" . $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( substr($output_number, 1), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } else { $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } $i++; } } elseif ( $this->output_number_letter_case == "upper" && $this->output_number_radix > 10 ) { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; if ($output_number[0] == "-") { $output_number = ""; while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } $this->output_numbers[0] = "-" . $this->output_number_prefix; $this->output_numbers[0] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } else { $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; if ($output_number[0] == "-") { $output_number = ""; while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } $this->output_numbers[$i] = "-" . $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } else { $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } $i++; } } else { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; if ($output_number[0] == "-") { $output_number = ""; while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } $this->output_numbers[0] = "-" . $this->output_number_prefix; $this->output_numbers[0] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } else { $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; } while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; if ($output_number[0] == "-") { $output_number = ""; while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } $this->output_numbers[$i] = "-" . $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } else { $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; } $i++; } } } else { if ($this->output_numbers[0] < 0) { $output_number = bcadd( strval(~$this->output_numbers[0]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[0]); } if ($this->output_number_radix == 10) { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; $i++; } } elseif ( $this->output_number_letter_case == "upper" && $this->output_number_radix > 10 ) { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( strtoupper($output_number), $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; $i++; } } else { $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[0] = $this->output_number_prefix; $this->output_numbers[0] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[0] .= $this->output_number_suffix; while ($i != $this->output_numbers_count) { if ($this->output_numbers[$i] < 0) { $output_number = bcadd( strval(~$this->output_numbers[$i]), "9223372036854775808" ); } else { $output_number = strval($this->output_numbers[$i]); } $output_number = bcadd( bcmod($output_number, $output_number_range_delta), $this->output_number_range_minimum ); $decimal_number = $output_number; $output_number = ""; if ($decimal_number != 0) { while ($decimal_number != 0) { $output_number = base_convert( intval(bcmod($decimal_number, $this->output_number_radix)), 10, $this->output_number_radix ) . $output_number; $decimal_number = bcdiv( $decimal_number, $this->output_number_radix, 0 ); } } else { $output_number = "0"; } $this->output_numbers[$i] = $this->output_number_prefix; $this->output_numbers[$i] .= str_pad( $output_number, $this->output_number_digits_minimum_count, "0", STR_PAD_LEFT ); $this->output_numbers[$i] .= $this->output_number_suffix; $i++; } } } return 0; } } $eightomic_randomize = new EightomicRandomize(); $eightomic_randomize->output_numbers_count = 10; $eightomic_randomize->output_number_letter_case = "upper"; $eightomic_randomize->output_number_digits_minimum_count = 3; $eightomic_randomize->output_number_prefix = "0x"; $eightomic_randomize->output_number_radix = 16; $eightomic_randomize->output_number_range_maximum = "1500"; $eightomic_randomize->output_number_range_minimum = "0"; $eightomic_randomize->output_number_signedness = "unsigned"; if ($eightomic_randomize->process() == 0) { print_r($eightomic_randomize->output_numbers); } ?>

Reference

$eightomic_randomize->process() is the randomization function that accepts the following optional arguments.

output_numbers_count is the amount of random numbers to generate. The minimum value is 1. The default value is 1.

output_number_digits_minimum_count is the minimum amount of digits in each random number with left-padded zeros. The default value is 1.

output_number_letter_case is the letter case of each generated random number if the value of output_number_radix is greater than 10. The default value is lower.

output_number_prefix is the prefix of each generated random number. The default value is empty.

output_number_radix is the number base of each generated random number. The maximum value is 36 and the minimum value is 2. The default value is 10.

output_number_range_maximum is the largest generated random number allowed. If the value of output_number_signedness is signed, the maximum value is 9223372036854775807 and the minimum value is -9223372036854775807. If the value of output_number_signedness is unsigned, the maximum value is 18446744073709551615 and the minimum value is 1. The default value is either 9223372036854775807 or 18446744073709551615 based on the output_number_signedness.

output_number_range_minimum is the smallest generated random number allowed. If the value of output_number_signedness is signed, the maximum value is 9223372036854775806 and the minimum value is -9223372036854775808. If the value of output_number_signedness is unsigned, the maximum value is 18446744073709551614 and the minimum value is 0. The default value is either -9223372036854775808 or 0 based on the output_number_signedness.

The value of output_number_range_maximum must be greater than the value of output_number_range_minimum.

output_number_signedness is the signedness of each generated random number. The value is either signed or unsigned. The default value is signed.

output_number_suffix is the suffix of each generated random number. The default value is empty.

Each response contains the following field.

output_numbers is the array of output_numbers_count number results, each as a formatted string.

The return value data type is an integer.

It returns a status code that corresponds with a status described in the following list.

0 means successful.

1 means the output_numbers_count value must be a number.

2 means the output_number_digits_minimum_count value must be a number.

3 means the output_number_letter_case value must be either lower or upper.

4 means the output_number_prefix value must be a string.

5 means the output_number_radix value must be a number.

6 means the output_number_radix value must be greater than or equal to 2.

7 means the output_number_radix value must be less than or equal to 32.

8 means the output_number_signedness value must be either signed or unsigned.

9 means the output_number_range_maximum value must be greater than or equal to -9223372036854775807 when the output_number_signedness value is signed.

10 means the output_number_range_maximum value must be less than or equal to 9223372036854775807 when the output_number_signedness value is signed.

11 means the output_number_range_maximum value must be greater than or equal to 1 when the output_number_signedness value is unsigned.

12 means the output_number_range_maximum value must be less than or equal to 18446744073709551615 when the output_number_signedness value is unsigned.

13 means the output_number_range_maximum value must be greater than or equal to -9223372036854775808 when the output_number_signedness value is signed.

14 means the output_number_range_minimum value must be less than or equal to 9223372036854775806 when the output_number_signedness value is signed.

15 means the output_number_range_minimum value must be greater than or equal to 0 when the output_number_signedness value is unsigned.

16 means the output_number_range_minimum value must be less than or equal to 18446744073709551614 when the output_number_signedness value is unsigned.

17 means the output_number_range_maximum value must be greater than the output_number_range_minimum value.

18 means the output_number_suffix value must be a string.

19 means server error.

Requirements

PHP 7.4+ with the BC Math extension.

High resolution system clock with nanosecond precision.

CPU that spends at least 5 nanoseconds processing each %, * and / operation.

Explanation

This hardware random number generator is designed as an efficient and error-resistant alternative to extracting classical bits of quantum randomness from collapsed qubits.

In quantum computing, the probability of capturing a result of either 0 or 1 after collapsing a superpositioned qubit is calculated with deterministic mathematical formulas.

These formulas depend on tangible quantum wave functions, which leverage entropic oscillations from external physical interactions.

The result is considered to be a reliable and scientifically-proven source of true randomness, which led to the creation of quantum random number generators (QRNGs).

As an alternative, the aforementioned TRNG library is capable of generating the same level of single-bit quantum entropy by combining classical and quantum computing methodologies.

It uses a computationally-expensive sequence of simulated qubit collapsing algorithms that rely on temporal mechanics to generate 64-bit, random binary numbers.

Time is clearly-defined as a simple measurement within the constraints of classical computing and physics.

Time changes at a constant, linear interval with a huge amount of precision relative to the third dimension.

In rare cases when the aforementioned CPU requirement isn't met, oscillation calculations can be amplified with manual changes to the code library. This may only be necessary on high-end devices with extremely-fast CPU speed to guarantee additional assurance of true randomness.

Otherwise, it's impossible for this TRNG to capture non-random, predetermined bits due to the verified temporal precision of the system clock on each implemented device far exceeding the fastest processing time of repeating computations between each random bit capture.

TNRG algorithms are computationally-expensive and slower compared to pseudo-random number generation algorithms, therefore this TRNG is only appropriate when high-quality randomness is an absolute requirement. For example, cryptographic applications, research data and deterministic PRNG state seeding may require true randomness.

Games

Contrivity Contrivity Icon

Contrivity

Spawn into the hostile quantum laboratory and destroy wave after wave of oscillations.

v1.0.14