= WSP-TRNG: A Quantum-Level Random Number Generator

WSP-TRNG: A Classical TRNG Algorithm With Quantum-Level Entropy Generating Random Numbers From CPU Oscillations and Temporal Precision Theory

William Stafford Parsons developed a truly-random integer generator with a temporal precision theory that guarantees randomness captured internally from quantum-level entropy as an alternative to using quantum computers.

Library

Source

#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <time.h> void _wsp_trng_handle_error(void) { exit(EXIT_FAILURE); } uint64_t _wsp_trng_64_oscillate(uint64_t entropy, uint64_t oscillation) { oscillation *= ((entropy / 11111111) % 111) + ((entropy + oscillation) % 111); oscillation /= (entropy - oscillation) | 1; oscillation = ((entropy + oscillation) % 65535) + 11111111; return oscillation; } uint64_t _wsp_trng_64_capture(uint64_t entropy, uint64_t *oscillation) { struct timespec s; if (clock_gettime(CLOCK_REALTIME, &s) == 0) { *oscillation += entropy; entropy = (entropy << 1) | (s.tv_nsec & 1); } else { _wsp_trng_handle_error(); } return entropy; } uint64_t wsp_trng_64_randomize(void) { uint64_t entropy = 1; uint64_t oscillation = 1111111111; while ((entropy >> 63) != 1) { oscillation = _wsp_trng_64_oscillate(entropy, oscillation); entropy = _wsp_trng_64_capture(entropy, &oscillation); } oscillation = _wsp_trng_64_oscillate(entropy, oscillation); entropy = _wsp_trng_64_capture(entropy, &oscillation); if (oscillation == 0) { oscillation = _wsp_trng_64_oscillate(entropy, oscillation); entropy = _wsp_trng_64_capture(entropy, &oscillation); } return entropy; } uint32_t _wsp_trng_32_oscillate(uint32_t entropy, uint32_t oscillation) { oscillation *= ((entropy / 111111) % 111) + ((entropy + oscillation) % 111); oscillation /= (entropy - oscillation) | 1; oscillation = ((entropy + oscillation) % 65535) + 111111; return oscillation; } uint32_t _wsp_trng_32_capture(uint32_t entropy, uint32_t *oscillation) { struct timespec s; if (clock_gettime(CLOCK_REALTIME, &s) == 0) { *oscillation += entropy; entropy = (entropy << 1) | (s.tv_nsec & 1); } else { _wsp_trng_handle_error(); } return entropy; } uint32_t wsp_trng_32_randomize(void) { uint32_t entropy = 1; uint32_t oscillation = 1111111111; while ((entropy >> 31) != 1) { oscillation = _wsp_trng_32_oscillate(entropy, oscillation); entropy = _wsp_trng_32_capture(entropy, &oscillation); } oscillation = _wsp_trng_32_oscillate(entropy, oscillation); entropy = _wsp_trng_32_capture(entropy, &oscillation); if (oscillation == 0) { oscillation = _wsp_trng_32_oscillate(entropy, oscillation); entropy = _wsp_trng_32_capture(entropy, &oscillation); } return entropy; } uint16_t _wsp_trng_16_oscillate(uint16_t entropy, uint16_t oscillation) { oscillation *= ((entropy / 11111) % 111) + ((entropy + oscillation) % 111); oscillation /= (entropy - oscillation) | 1; oscillation = ((entropy + oscillation) % 65535) + 11111; return oscillation; } uint16_t _wsp_trng_16_capture(uint16_t entropy, uint16_t *oscillation) { struct timespec s; if (clock_gettime(CLOCK_REALTIME, &s) == 0) { *oscillation += entropy; entropy = (entropy << 1) | (s.tv_nsec & 1); } else { _wsp_trng_handle_error(); } return entropy; } uint16_t wsp_trng_16_randomize(void) { uint16_t entropy = 1; uint16_t oscillation = 11111; while ((entropy >> 15) != 1) { oscillation = _wsp_trng_16_oscillate(entropy, oscillation); entropy = _wsp_trng_16_capture(entropy, &oscillation); } oscillation = _wsp_trng_16_oscillate(entropy, oscillation); entropy = _wsp_trng_16_capture(entropy, &oscillation); if (oscillation == 0) { oscillation = _wsp_trng_16_oscillate(entropy, oscillation); entropy = _wsp_trng_16_capture(entropy, &oscillation); } return entropy; } uint8_t _wsp_trng_8_oscillate(uint8_t entropy, uint8_t oscillation) { oscillation *= ((entropy / 111) % 111) + ((entropy + oscillation) % 111); oscillation /= (entropy - oscillation) | 1; oscillation = ((entropy + oscillation) % 65535) + 111; return oscillation; } uint8_t _wsp_trng_8_capture(uint8_t entropy, uint8_t *oscillation) { struct timespec s; if (clock_gettime(CLOCK_REALTIME, &s) == 0) { *oscillation += entropy; entropy = (entropy << 1) | (s.tv_nsec & 1); } else { _wsp_trng_handle_error(); } return entropy; } uint8_t wsp_trng_8_randomize(void) { uint8_t entropy = 1; uint8_t oscillation = 111; while ((entropy >> 7) != 1) { oscillation = _wsp_trng_8_oscillate(entropy, oscillation); entropy = _wsp_trng_8_capture(entropy, &oscillation); } oscillation = _wsp_trng_8_oscillate(entropy, oscillation); entropy = _wsp_trng_8_capture(entropy, &oscillation); if (oscillation == 0) { oscillation = _wsp_trng_8_oscillate(entropy, oscillation); entropy = _wsp_trng_8_capture(entropy, &oscillation); } return entropy; }

Reference

wsp_trng_64_randomize() is the 64-bit randomization function.

The return value data type is uint64_t.

It returns the 64-bit unsigned integer random number result.

wsp_trng_32_randomize() is the 32-bit randomization function.

The return value data type is uint32_t.

It returns the 32-bit unsigned integer random number result.

wsp_trng_16_randomize() is the 16-bit randomization function.

The return value data type is uint16_t.

It returns the 16-bit unsigned integer random number result.

wsp_trng_8_randomize() is the 8-bit randomization function.

The return value data type is uint8_t.

It returns the 8-bit unsigned integer random number result.

Requirements

C compiler with C99 (ISO/IEC 9899:1999) standard compatibility.

POSIX-compatible system with conformance to POSIX.1-2001, POSIX.1-2008 and SUSv2.

System with resilience to the year 2038 problem.

clock_gettime() implementation that supports high-resolution, system-wide clock reads with guaranteed nanosecond time precision using CLOCK_REALTIME. If this is unavailable or not guaranteed by the implementation, the std::chrono library in C++ may offer a sensible alternative.

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

Explanation

WSP-TRNG is designed as an efficient and error-resistant alternative to extracting classical bits of quantum randomness from collapsed qubits.

It's compatible with both 32-bit and 64-bit POSIX systems with the exception of wsp_trng_64_randomize() for 64-bit POSIX systems.

The aforementioned library code in POSIX C is only intended to demonstrate an example using the following TRNG system and should be subject to heavy scrutiny of local system clock reliability before implementing into any critical system.

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 should be amplified in _wsp_trng_16_oscillate() 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.

The conditional statement if (oscillation == 0) captures an additional random bit in rare instances to ensure oscillation doesn't pollute entropy without unintentionally removing CPU oscillations with compiler optimization liberties.

The aforementioned TRNG algorithm produces bits that are as random as possible while setting the standard of true entropy within the constraints of time. Theoretical randomness and denying the existence of free will beyond these computations is the topic of an irrelevant philisophical discussion.

It usually fails statistical randomness tests for 8-bit, 16-bit, 32-bit and 64-bit numbers after a few KB of output, which means it's a solid basis for researching new and improved computational analyses of random number quality. If generating random-looking numbers which consistently pass statistical test suites is a priority instead of true randomness, then implementing a deterministic PRNG that re-seeds with WSP-TRNG is a sensible alternative.

System clock failures are handled by abruptly stopping with exit(EXIT_FAILURE), but alternate error handling methods may be appropriate in specific implementations, such as falling back to reading /dev/random, querying a trusted QRNG API or using a seeded PRNG.

A TNRG algorithm is computationally-expensive and slower compared to a pseudo-random number generation algorithm, therefore this TRNG is only appropriate when true randomness is an absolute requirement where speed isn't critical. For example, deterministic PRNG state seeding and research data may require true randomness.

It may be suitable for cryptographic applications as well, but it hasn't received NIST analysis results or approval.

Games

ContrivityContrivity Icon

Contrivity

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