Added gallery.
This commit is contained in:
11
sampling.cpp
11
sampling.cpp
@@ -1,5 +1,4 @@
|
||||
#ifdef _USE_CPP11_RANDOM
|
||||
#warning "Using C++11 random number generators."
|
||||
#ifdef USE_CPP11_RANDOM
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
@@ -13,7 +12,7 @@
|
||||
|
||||
#include "sampling.hpp"
|
||||
|
||||
#ifdef _USE_CPP11_RANDOM
|
||||
#ifdef USE_CPP11_RANDOM
|
||||
using std::uniform_real_distribution;
|
||||
using std::mt19937;
|
||||
using std::bind;
|
||||
@@ -29,7 +28,7 @@ const float PDF = (1.0f / (2.0f * pi<float>()));
|
||||
|
||||
static bool seeded = false;
|
||||
|
||||
#ifdef _USE_CPP11_RANDOM
|
||||
#ifdef USE_CPP11_RANDOM
|
||||
static uniform_real_distribution<float> dist(0, 1);
|
||||
static mt19937 engine;
|
||||
static auto generator = bind(dist, engine);
|
||||
@@ -37,14 +36,14 @@ static auto generator = bind(dist, engine);
|
||||
|
||||
float random01() {
|
||||
if (!seeded) {
|
||||
#ifdef _USE_CPP11_RANDOM
|
||||
#ifdef USE_CPP11_RANDOM
|
||||
engine.seed(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
#else
|
||||
srand(time(NULL));
|
||||
#endif
|
||||
seeded = true;
|
||||
}
|
||||
#ifdef _USE_CPP11_RANDOM
|
||||
#ifdef USE_CPP11_RANDOM
|
||||
return generator();
|
||||
#else
|
||||
return static_cast<float>(rand()) / RAND_MAX;
|
||||
|
Reference in New Issue
Block a user