diff --git a/README.md b/README.md index ebf70de..0217fd9 100644 --- a/README.md +++ b/README.md @@ -37,18 +37,52 @@ FetchContent_MakeAvailable(crng) Here's a simple example of how to generate random numbers using OpenRAND: ``` -#include "OpenRAND/random.hpp" -#include +#include int main() { - OpenRAND::RandomEngine rng; + using RNG = Phillox; // Tyche + + // Initialize RNG with seed and counter + RNG rng(1, 0); + + // Draw random numbers of many types + int a = rng.rand(); + auto b = rng.rand(); + double c = rng.rand(); + float f = rng.rand(); + ... +} +``` + +The seed should correspond a work-unit or processing element of the program. For example, it could be the unique global id of a particle in a monte carlo simulation, or the pixel flat index in a ray tracing renderer. The counter should be incremented every time a new random number is drawn for a particular seed. This is helpful, for example, when a particle undergoes multiple kernel launches (with a new random stream required in each) in it's lifespan. + +``` +__global__ void apply_forces(Particle *particles, int counter, double sqrt_dt){ + int i = blockIdx.x * blockDim.x + threadIdx.x; + ... + + // Apply random force + RNG local_rand_state(p.pid, counter); + + //double2 r = curand_uniform2_double(&local_rand_state); + auto x = local_rand_state.rand(); + auto y = local_rand_state.rand(); + p.vx += (x * 2.0 - 1.0) * sqrt_dt; + p.vy += (y * 2.0 - 1.0) * sqrt_dt; + particles[i] = p; + +} - // Generate a random integer between 1 and 100 - int random_number = rng.randint(1, 100); - std::cout << "Random Number: " << random_number << std::endl; +int main(){ + ... - return 0; + // Simulation loop + int iter = 0; + while (iter++ < STEPS) { + apply_forces<<>>(particles, iter, sqrt_dt); + ... + } } ```