| Crates.io | rust_qrng |
| lib.rs | rust_qrng |
| version | 0.1.2 |
| created_at | 2025-07-07 12:36:38.438984+00 |
| updated_at | 2025-07-07 12:49:53.921969+00 |
| description | Tsotchkes quantum random number generator library with cryptographic, financial, and gaming applications converted to Rust |
| homepage | https://github.com/ingen0s/quantum_rng_rust_lib |
| repository | https://github.com/ingen0s/quantum_rng_rust_lib |
| max_upload_size | |
| id | 1741169 |
| size | 77,846 |
A high-quality quantum random number generator library for Rust applications requiring cryptographically secure randomness. This library provides quantum-enhanced random number generation with specialized modules for cryptography, finance, games, and statistical analysis based on Tsotchke QRNG.
Add this to your Cargo.toml:
[dependencies]
rust_qrng = "0.1"
use rust_qrng::quantum_rng;
fn main() {
// Create a new quantum RNG instance
let mut rng = quantum_rng::new();
// Generate random numbers
let random_u64 = rng.generate_u64();
let random_f64 = rng.generate_f64();
println!("Random u64: {}", random_u64);
println!("Random f64: {}", random_f64);
}
use rust_qrng::crypto::{key_exchange, key_derivation};
// Generate cryptographic keys
let key_pair = key_exchange::generate_keypair();
let derived_key = key_derivation::derive_key(&key_pair.private, b"salt");
use rust_qrng::finance::monte_carlo;
// Run Monte Carlo simulation
let simulation = monte_carlo::SimulationBuilder::new()
.iterations(10000)
.initial_value(100.0)
.volatility(0.2)
.build();
let results = simulation.run();
println!("Expected value: {}", results.mean());
use rust_qrng::games::quantum_dice;
// Roll quantum dice
let dice = quantum_dice::QuantumDice::new(6); // 6-sided die
let roll = dice.roll();
println!("Rolled: {}", roll);
use rust_qrng::statistical::tests;
// Test randomness quality
let mut rng = rust_qrng::quantum_rng::new();
let samples: Vec<f64> = (0..1000).map(|_| rng.generate_f64()).collect();
let chi_square_result = tests::chi_square_test(&samples);
println!("Chi-square test p-value: {}", chi_square_result.p_value);
use rust_qrng::quantum_rng;
// Create a new quantum RNG instance
let mut rng = quantum_rng::new();
// Generate different types of random numbers
let u64_value = rng.generate_u64(); // 64-bit unsigned integer
let f64_value = rng.generate_f64(); // 64-bit floating point (0.0 to 1.0)
let bool_value = rng.generate_bool(); // Boolean value
let range_value = rng.generate_range(1, 100); // Integer in range [1, 100)
use rust_qrng::crypto::{key_exchange, key_derivation};
// Generate RSA key pair
let keypair = key_exchange::generate_keypair();
// Derive key from master key
let derived_key = key_derivation::derive_key(
&keypair.private,
b"application_salt",
);
use rust_qrng::finance::{monte_carlo, options_pricing};
// Monte Carlo simulation
let simulation = monte_carlo::SimulationBuilder::new()
.iterations(100_000)
.initial_value(100.0)
.volatility(0.25)
.drift(0.05)
.time_horizon(1.0)
.build();
let results = simulation.run();
println!("Mean: {:.2}", results.mean());
println!("Std Dev: {:.2}", results.std_dev());
println!("VaR (95%): {:.2}", results.var_95());
// Options pricing
let option_price = options_pricing::black_scholes(
100.0, // Spot price
110.0, // Strike price
0.25, // Time to expiration (years)
0.05, // Risk-free rate
0.2, // Volatility
);
use rust_qrng::games::quantum_dice;
// Create quantum dice
let d6 = quantum_dice::QuantumDice::new(6);
let d20 = quantum_dice::QuantumDice::new(20);
// Roll dice
let roll = d6.roll();
println!("D6 roll: {}", roll);
// Multiple rolls
let rolls = d20.roll_multiple(5);
println!("D20 rolls: {:?}", rolls);
use rust_qrng::statistical::tests;
// Generate test data
let mut rng = rust_qrng::quantum_rng::new();
let samples: Vec<f64> = (0..10000)
.map(|_| rng.generate_f64())
.collect();
// Perform statistical tests
let chi_square = tests::chi_square_test(&samples);
let kolmogorov_smirnov = tests::ks_test(&samples);
let runs_test = tests::runs_test(&samples);
println!("Chi-square p-value: {:.4}", chi_square.p_value);
println!("K-S p-value: {:.4}", kolmogorov_smirnov.p_value);
println!("Runs test p-value: {:.4}", runs_test.p_value);
The library is optimized for both quality and performance:
Run the test suite to verify functionality:
# Run all tests
cargo test
# Run specific test module
cargo test statistical
# Run with output
cargo test -- --nocapture
Run benchmarks to measure performance:
cargo bench
Complete examples are available in the examples/ directory:
# Basic usage
cargo run --example quantum_rng_demo
# Cryptographic key generation
cargo run --example key_exchange_demo
# Monte Carlo simulation
cargo run --example monte_carlo_demo
# Quantum dice game
cargo run --example quantum_dice_demo
# Quantum blockchain
cargo run --example quantum_chain_demo
Contributions are welcome! Please feel free to submit a pull request or open an issue for any suggestions or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.