An experimental C/C++/CUDA project exploring:
- Optimized prime sieving (CPU + multi-GPU CUDA)
- Accurate dice randomness for tabletop and RPG mechanics
- Physically simulated dice rolls using NVIDIA PhysX
- Auto-tuned performance across CPU/GPU hardware
- Live visualization with the PhysX Visual Debugger (PVD)
| Component | Description |
|---|---|
| OSE / CUDA Sieve | Optimized Sieve of Eratosthenes segmented, odd-only, GPU-parallel, JSON export |
| Dice Engine (CPU) | Pure math engine for NdM+K expressions unbiased, optional prime-seeded randomness, chi-square validation |
| PhysX Dice Simulator | Fully physical D6, D8, D12, D20 dice with realistic collisions, ramp chute, multi-threading, and GPU acceleration |
| Visualization | Optional live streaming via --pvd to PhysX Visual Debugger or NVIDIA Omniverse View |
| Data Outputs | JSON and CSV result logging, with chi-square test of fairness and probability distribution graphs |
- CMake 3.20
- C++17 compiler (clang / gcc / MSVC)
- (Optional) CUDA Toolkit (for GPU sieve)
- (Optional) NVIDIA PhysX SDK (for physics dice)
- (Optional) PhysX Visual Debugger (PVD) to visualize rolls live
mkdir build && cd build
cmake .. -DBUILD_CUDA_SIEVE_MGPU=ON -DBUILD_PHYSX_DICE=ON
cmake --build . -jTesla K80 users: CUDA architecture defaults to
sm_37.
Override with:
-DCMAKE_CUDA_ARCHITECTURES=37(or80for A100s, etc.)
# Fair D6, 10k rolls, chi-square test
./dice_cpu --faces 6 --count 10000 --chi
# D20, 20k rolls, prime-seeded, CSV output
./dice_cpu --faces 20 --count 20000 --use-prime-seeds primes_50M.json --csv d20.csv --chi
# RPG Expression Example
./dice_cpu --spec "3d6+2" --count 5000 --use-prime-seeds primes_50M.json --log-json rolls.json --chiFlags
--spec NdM+KDice expression (can repeat)--count NNumber of rolls per set--chiEnable chi-square fairness check--csv/--log-jsonโ�� Export results
./cuda_sieve_mgpu 50000000 --gpus 4 --seg 256M --json primes_50M.jsonGenerates all primes 50 M using up to four Tesla K80 GPUs, writing them to primes_50M.json.
# Basic D6 simulation with 50k rolls and chi-square test
./physx_dice_multi --spec 1d6 --trials 50000 --chi
# Complex run with multiple dice, chute ramp, PVD visualization, and JSON/CSV output
./physx_dice_multi --spec 3d6+2 --spec 1d8 --spec 1d12 --spec 1d20 --trials 20000 --use-prime-seeds primes_50M.json --chute --pvd 127.0.0.1:5425 --json physx_runs.json --csv physx_counts.csv --chiFlags
--chuteAdds an angled ramp, side walls, and backstop for realism--pvd [host:port]Stream live to PhysX Visual Debugger (default: 127.0.0.1 : 5425)--use-prime-seedsDeterministic seed list from JSON primes--json/--csvWrite results to disk
Make sure PVD is running before launching your sim to see live dice tumbling!
##��� Repository Layout
code-noodling/
��CMakeLists.txt
��.gitignore
��cuda_sieve_mgpu.cu
dice_cpu.cpp
��physx_dice_multi.cpp
��die_mesh.h
��OSE.c (optional legacy)
OSE_CUDA.cc (optional legacy)
��README.md
��primes_50M.json (generated at runtime)
- Hardware autodetect: automatically uses all CPU threads and available CUDA devices.
- Deterministic seeding: optional uses primes for stable pseudo-random sequences.
- PhysX cooking: convex meshes generated internally for D8, D12, D20 via
die_mesh.h. - Chute geometry: procedural ramp (30° tilt) + sidewalls + backstop.
- Visualization: controlled via
--pvd; debug draw enabled for collision shapes & contacts. - Data outputs: JSON + CSV + chi-square test summary.
# Step 1 โ�� Generate prime seeds
./cuda_sieve_mgpu 50000000 --json primes_50M.json
# Step 2 โ�� Simulate physical dice using those seeds
./physx_dice_multi --spec 2d6+3 --trials 10000 --use-prime-seeds primes_50M.json --chute --pvd --chiDonovan Worrell
Seattle, WA, USA
donovan.worrell@gmail.com
MIT License ยฉ 2025 Donovan Worrell
Permission is granted to use, modify, and distribute this software with attribution.