Three files showing how to use it:
Random.h
- header file for the libraryRandom.cpp
- implementations of functions generating RNs from different distributions, but using the same enginegetRandomMulti.cpp
- examples how to do it in a multi-threading environmentmutatorTest.cpp
- simple program scaling 'whole-bitsting mutation' to 'point mutations' in binary strings and checking if the scaling gives the same fraction of altered bitsting https://ndownloader.figshare.com/files/2546683
Compiles with g++ 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) and runs e.g. by typing
g++ -o rands Random.cpp getRandomMulti.cpp -O2 -std=c++11 -fopenmp
./rands
You can check the results in Ipython:
%pylab
ww0 = np.genfromtxt("randomz_0.dat", skip_header=1)
ww1 = np.genfromtxt("randomz_1.dat", skip_header=1)
ww2 = np.genfromtxt("randomz_2.dat", skip_header=1)
hh = plt.hist(np.hstack((ww0, ww1, ww2)))
- Regarding the multi-threading programming in C++11 here's a guide into OpenMP: https://bisqwit.iki.fi/story/howto/openmp/
- For more tips how to use the
<random>
library in C++11 see: https://isocpp.org/files/papers/n3551.pdf - For using std::discrete_distribution with user defined weights: https://en.cppreference.com/w/cpp/numeric/random/piecewise_constant_distribution