From 0eefc75864244e58465b2682660a9cb8db5ece9e Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 11 Feb 2020 11:38:31 +0100 Subject: [PATCH] changed: use std::random instead of boost::random also use lambdas instead of bind --- examples/cpchop.cpp | 24 ++++++++++-------------- examples/cpchop_depthtrend.cpp | 18 +++++++----------- examples/exp_variogram.cpp | 22 +++++++++------------- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/examples/cpchop.cpp b/examples/cpchop.cpp index 3f3e9ef..74067f4 100644 --- a/examples/cpchop.cpp +++ b/examples/cpchop.cpp @@ -48,10 +48,7 @@ #include -#include -#include -#include -#include +#include int main(int argc, char** argv) try @@ -88,7 +85,7 @@ try bool upscale = param.getDefault("upscale", true); std::string bc = param.getDefault("bc", "fixed"); bool resettoorigin = param.getDefault("resettoorigin", true); - boost::mt19937::result_type userseed = param.getDefault("seed", 0); + std::mt19937::result_type userseed = param.getDefault("seed", 0); bool use_random = param.getDefault("use_random", true); int outputprecision = param.getDefault("outputprecision", 8); @@ -234,12 +231,11 @@ try jmin, jlen, jmax, zmin, zlen, zmax); - // Random number generator from boost. - boost::mt19937 gen; + std::mt19937 gen; // Seed the random number generators with the current time, unless specified on command line // Warning: Current code does not allow 0 for the seed!! - boost::mt19937::result_type autoseed = time(NULL); + std::mt19937::result_type autoseed = time(NULL); if (userseed == 0) { gen.seed(autoseed); } @@ -273,12 +269,12 @@ try } // Note that end is included in interval for uniform_int. - boost::uniform_int<> disti(imin, imax - ilen); - boost::uniform_int<> distj(jmin, jmax - jlen); - boost::uniform_real<> distz(zmin, std::max(zmax - zlen, zmin+1e-6)); - boost::variate_generator > ri(gen, disti); - boost::variate_generator > rj(gen, distj); - boost::variate_generator > rz(gen, distz); + std::uniform_int_distribution<> disti(imin, imax - ilen); + std::uniform_int_distribution<> distj(jmin, jmax - jlen); + std::uniform_real_distribution<> distz(zmin, std::max(zmax - zlen, zmin+1e-6)); + auto ri = [&disti, &gen] { return disti(gen); }; + auto rj = [&distj, &gen] { return distj(gen); }; + auto rz = [&distz, &gen] { return distz(gen); }; // Storage for results std::vector porosities; diff --git a/examples/cpchop_depthtrend.cpp b/examples/cpchop_depthtrend.cpp index b54cfe0..2eec8db 100644 --- a/examples/cpchop_depthtrend.cpp +++ b/examples/cpchop_depthtrend.cpp @@ -45,10 +45,7 @@ #include -#include -#include -#include -#include +#include /** This program is a variant of cpchop. Instead of subsampling randomly, @@ -93,7 +90,7 @@ try double zlen = param.getDefault("zlen", zresolution); bool upscale = param.getDefault("upscale", true); bool resettoorigin = param.getDefault("resettoorigin", true); - boost::mt19937::result_type userseed = param.getDefault("seed", 0); + std::mt19937::result_type userseed = param.getDefault("seed", 0); int outputprecision = param.getDefault("outputprecision", 8); std::string filebase = param.getDefault("filebase", ""); @@ -122,8 +119,7 @@ try jmin, jlen, jmax, zmin, zlen, zmax); - // Random number generator from boost. - boost::mt19937 gen; + std::mt19937 gen; // Seed the random number generators with the current time, unless specified on command line // Warning: Current code does not allow 0 for the seed!! @@ -136,10 +132,10 @@ try // Note that end is included in interval for uniform_int. - boost::uniform_int<> disti(imin, imax - ilen); - boost::uniform_int<> distj(jmin, jmax - jlen); - boost::variate_generator > ri(gen, disti); - boost::variate_generator > rj(gen, distj); + std::uniform_int_distribution<> disti(imin, imax - ilen); + std::uniform_int_distribution<> distj(jmin, jmax - jlen); + auto ri = [&disti, &gen] { return disti(gen); }; + auto rj = [&distj, &gen] { return distj(gen); }; // Storage for results std::vector zstarts; diff --git a/examples/exp_variogram.cpp b/examples/exp_variogram.cpp index 4afc91f..84ce99c 100644 --- a/examples/exp_variogram.cpp +++ b/examples/exp_variogram.cpp @@ -56,10 +56,7 @@ #include -#include -#include -#include -#include +#include int main(int argc, char** argv) try @@ -84,7 +81,7 @@ try int ilen = param.getDefault("ilen", 0); int jlen = param.getDefault("jlen", 0); double zlen = param.getDefault("zlen", 0.0); - boost::mt19937::result_type userseed = param.getDefault("seed", 0); + std::mt19937::result_type userseed = param.getDefault("seed", 0); int outputprecision = param.getDefault("outputprecision", 8); std::string resultfile = param.getDefault("resultfile", ""); @@ -145,8 +142,7 @@ try jmin, jlen, jmax, zmin, zlen, zmax); - // Random number generator from boost. - boost::mt19937 gen; + std::mt19937 gen; // Seed the random number generators with the current time, unless specified on command line // Warning: Current code does not allow 0 for the seed!! @@ -159,12 +155,12 @@ try // Note that end is included in interval for uniform_int. - boost::uniform_int<> disti(imin, imax - ilen); - boost::uniform_int<> distj(jmin, jmax - jlen); - boost::uniform_real<> distz(zmin, std::max(zmax - zlen, zmin)); - boost::variate_generator > ri(gen, disti); - boost::variate_generator > rj(gen, distj); - boost::variate_generator > rz(gen, distz); + std::uniform_int_distribution<> disti(imin, imax - ilen); + std::uniform_int_distribution<> distj(jmin, jmax - jlen); + std::uniform_real_distribution<> distz(zmin, std::max(zmax - zlen, zmin)); + auto ri = [&disti, &gen] { return disti(gen); }; + auto rj = [&distj, &gen] { return distj(gen); }; + auto rz = [&distz, &gen] { return distz(gen); }; // Storage for results std::vector distances;