🤏 lds-rs - Low-Discrepancy Sequence Generator in Rust
Overview
This library provides a set of low-discrepancy sequence generators that create sequences of numbers that are more evenly distributed than random numbers. These sequences are particularly useful in various fields such as computer graphics, numerical integration, and Monte Carlo simulations.
All sequence generators are thread-safe, using atomic operations for internal state management, making them safe to use in concurrent environments.
Features
- van der Corput sequence: Base implementation for 1D sequences
- Halton sequence: 2D and N-dimensional sequences using different bases
- Geometric sequences:
Circle: Points on the unit circleDisk: Points in the unit diskSphere: Points on the unit sphereSphere3Hopf: Points on the 3-sphere using Hopf fibration
- N-dimensional spheres:
Sphere3: Points on 3-sphere (4D)SphereN: Points on n-sphere for arbitrary dimensions
- Integer sequences: Integer versions of van der Corput and Halton sequences
- Thread-safe: All generators use atomic operations for safe concurrent access
- Prime table: First 1000 prime numbers for use as sequence bases
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic van der Corput Sequence
use VdCorput;
let mut vgen = new;
vgen.reseed;
println!; // 0.5
println!; // 0.25
2D Halton Sequence
use Halton;
let mut hgen = new;
hgen.reseed;
let point = hgen.pop;
println!; // [0.5, 0.3333333333333333]
Points on a Sphere
use Sphere;
let mut sgen = new;
sgen.reseed;
let point = sgen.pop;
println!; // Point on unit sphere
N-Dimensional Spheres
use ;
// 3-sphere (4D)
let mut sgen3 = new;
sgen3.reseed;
let point3 = sgen3.pop;
println!; // 4D point on unit 3-sphere
// n-sphere (5D)
let mut sgen_n = new;
sgen_n.reseed;
let point_n = sgen_n.pop;
println!; // 5D point on unit 4-sphere
The sphere generators use thread-safe lazy initialization and caching for optimal performance in concurrent environments.
Integer Sequences
use ;
// Integer van der Corput
let mut ivdc = new;
ivdc.reseed;
println!; // 512
// Integer Halton
let mut ihalton = new;
ihalton.reseed;
let int_point = ihalton.pop;
println!; // [1024, 729]
Thread-safe Usage
All sequence generators are thread-safe and can be safely shared across threads:
use Arc;
use thread;
use Halton;
let halton = new;
halton.reseed;
let mut handles = vec!;
for _ in 0..4
for handle in handles
API Reference
Core Types
VdCorput: van der Corput sequence generator (thread-safe)Halton: 2D Halton sequence generator (thread-safe)Circle: Unit circle sequence generator (thread-safe)Disk: Unit disk sequence generator (thread-safe)Sphere: Unit sphere sequence generator (thread-safe)Sphere3Hopf: 3-sphere sequence generator using Hopf coordinates (thread-safe)HaltonN: N-dimensional Halton sequence generator (thread-safe)
N-Dimensional Sphere Types (in sphere_n module)
sphere_n::SphereGen: Thread-safe trait for sphere generators (implements Send)sphere_n::Sphere3: Thread-safe 3-sphere (4D) sequence generatorsphere_n::SphereN: Thread-safe N-sphere sequence generator for arbitrary dimensions
Integer Types (in ilds module)
ilds::VdCorput: Integer van der Corput sequence generator (thread-safe)ilds::Halton: Integer 2D Halton sequence generator (thread-safe)
Constants
TWO_PI: Constant for 2πPRIME_TABLE: First 1000 prime numbers
Examples
See the examples directory for more usage examples.
Testing
Run the tests with:
🛠️ Installation
📦 Cargo
- Install the rust toolchain in order to have cargo installed by following this guide.
- run
cargo install lds-rs
📜 License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
🤝 Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See CONTRIBUTING.md.