summaryrefslogtreecommitdiff
path: root/src/random.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/random.h')
-rw-r--r--src/random.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/random.h b/src/random.h
new file mode 100644
index 0000000..74329da
--- /dev/null
+++ b/src/random.h
@@ -0,0 +1,22 @@
+#ifndef __RANDOM_H__
+#define __RANDOM_H__
+
+#include <curand_kernel.h>
+
+#include "physical_constants.h"
+
+__device__ float uniform(curandState *rng, float a=0.0, float b=1.0)
+{
+ return a + curand_uniform(rng)*(b-a);
+}
+
+__device__ float3 uniform_sphere(curandState *rng)
+{
+ float theta = uniform(rng, 0, 2*PI);
+ float u = uniform(rng, -1, 1);
+ float c = sqrtf(1-u*u);
+
+ return make_float3(c*cosf(theta), c*sinf(theta), u);
+}
+
+#endif