qcoin - Quantum Coin Toss
A quantum-based binary choice maker that performs coin tosses using quantum random number generators. The application tries multiple quantum sources and uses a mix of cryptographically secure RNGs seeded with the quantum bytes obtained from a publicly available QRNG.
Installation
You can build the project from source or install it directly from crates.io.
Usage
Note: Running qcoin in quick succession may fail due to API rate limits. If this happens, please wait and try again later. In the meantime, qcoin will reuse the quantum bytes saved in qrandom.bytes from a previous successful request.
Command Line Options
| Flag | Description | Default | Notes |
|---|---|---|---|
<number> |
Number of coin flips | 1 |
First positional argument |
-o, --out <file> |
Output file for quantum entropy | qrandom.bytes |
Only saves when quantum sources succeed |
Note: If the specified output file already exists, the program will warn and use the default file instead.
How it Works
Entropy Source Priority
The application attempts to fetch truly random bytes from sources in this order:
- 🔬 ANU QRNG - Australian National University's Quantum Random Number Generator
- 🌐 qrandom.io
- 🔒 Cryptographic SRNG - Cryptographically secure random number generator (fallback)
- ♻️ Saved Quantum Bytes - Previously saved quantum entropy from
qrandom.bytes
Core Logic
The program implements a hybrid approach for multiple coin flips:
Single Flip (N=1)
- Uses quantum bytes directly to count 1s vs 0s
- Pure quantum randomness determines the outcome
Multiple Flips (N>1)
- N-1 flips: Generated using a CSRNG seeded with quantum entropy
- 1 flip: Uses the original quantum bytes directly
- Parallel processing: CSRNG flips are generated in parallel for performance
This approach ensures:
- At least one flip always uses pure quantum randomness
- Computational efficiency for large numbers of flips
- Deterministic results when using the same quantum seed
Example Flow for 10 Flips
- Fetch 1024 quantum bytes from ANU QRNG
- Save quantum bytes to
qrandom.bytes - Generate 9 flips (9 × 1024 = 9,216 bytes) using quantum-seeded CSRNG
- Use the original 1024 quantum bytes for the 10th flip
- Count total 1s vs 0s across all 10,240 bytes
- Determine outcome: more 1s = YES, more 0s = NO
Output
🎲 Quantum Coin Toss
📊 Flips: 10
🔍 Trying ANU QRNG...
✅ ANU QRNG: 1024 bytes
💾 Saved quantum entropy to file
🌱 Using quantum seed for 10 flips (9 CSRNG + 1 quantum)
⚡ Generating 9216 bytes from seeded CSRNG (9 flips)
✅ Generated 9216 bytes from CSRNG
🔬 Using quantum entropy directly for final flip
📈 Result: 40,960 ones, 40,944 zeros
🎯 Outcome: YES
Dependencies
rand- Cryptographic random number generation and seedingreqwest- HTTP client for quantum API requestsserde- JSON parsing for API responsesrayon- Parallel processing for multiple flipshex- Hexadecimal encoding/decoding utilitiessha2- SHA-2 cryptographic hash functions