// // simple use of C++11 random number generator, // for single-threaded applications, producing // one random number at a time // #include #include // C++11 random number generators #include // define ncff (Normal CDF function) float ncff(float x){ return 0.5f+0.5f*erff(sqrtf(0.5f)*x); } // declare generator and output distributions // see https://www.cplusplus.com/reference/random/ std::default_random_engine rng; std::uniform_real_distribution uniform(0.0f,1.0f); std::normal_distribution normal(0.0f,1.0f); auto next_uniform = std::bind(std::ref(uniform), std::ref(rng)); auto next_normal = std::bind(std::ref(normal), std::ref(rng)); int main(int argc, char **argv) { rng.seed(1234); uniform.reset(); normal.reset(); printf("uniforms:"); for (int i=0; i<10; i++) printf(" %6.3f",next_uniform()); printf("\n\nnormals: "); for (int i=0; i<10; i++) printf(" %6.3f",next_normal()); printf("\n\n"); }