I want to use 128 Bit pseudo random function generator in my acadmic project. But i did not found. Can any one please tell where i can get it in c++ or c language.
Thanks in advance
I want to use 128 Bit pseudo random function generator in my acadmic project. But i did not found. Can any one please tell where i can get it in c++ or c language.
Thanks in advance
If you use the Boost.Random library, there are plenty of different random number generators with all sorts of cycle lengths (including 2300000 bits).
The new C++ standard (C++11) also includes a random library with a lot of the generators from the Boost.Random library, but you need a fairly recent compiler to have that available. You can also use the underlying random number engines to create custom generators, the methods available are linear-congruential, mersenne-twister, subtract-with-carry, discard-block, independent-bits, and shuffle-order engines. There are plenty of options.
If you use the Boost.Random library, there are plenty of different random number generators with all sorts of cycle lengths (including 2300000 bits).
The new C++ standard (C++11) also includes a random library with a lot of the generators from the Boost.Random library, but you need a fairly recent compiler to have that available. You can also use the underlying random number engines to create custom generators, the methods available are linear-congruential, mersenne-twister, subtract-with-carry, discard-block, independent-bits, and shuffle-order engines. There are plenty of options.
Thank you for your valuable comment or suggestion.
I found /usr/include/boost/random/linear_congruential.hpp library. Can you please one example using rand48 class in this library.
Yeah sure, here's an example:
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/normal_distribution.hpp>
#include <iostream>
#include <ctime>
int main() {
boost::random::rand48 rng = boost::random::rand48((unsigned int)time(NULL));
std::cout << " This is a random number: " << rng() << std::endl;
boost::random::uniform_01<double> udist;
std::cout << " This is a uniformly distributed 'double' value in range [0,1]: " << udist(rng) << std::endl;
boost::random::normal_distribution<double> ndist(0.5, 0.25);
std::cout << " This is a normally distributed 'double' value with mean 0.5 and std-dev 0.25: " << ndist(rng) << std::endl;
return 0;
};
Yeah sure, here's an example:
#include <boost/random/linear_congruential.hpp> #include <boost/random/uniform_01.hpp> #include <boost/random/normal_distribution.hpp> #include <iostream> #include <ctime> int main() { boost::random::rand48 rng = boost::random::rand48((unsigned int)time(NULL)); std::cout << " This is a random number: " << rng() << std::endl; boost::random::uniform_01<double> udist; std::cout << " This is a uniformly distributed 'double' value in range [0,1]: " << udist(rng) << std::endl; boost::random::normal_distribution<double> ndist(0.5, 0.25); std::cout << " This is a normally distributed 'double' value with mean 0.5 and std-dev 0.25: " << ndist(rng) << std::endl; return 0; };
Thankyou mike
but when i am running this it gives
../random_gen.cpp: In function ‘int main()’:
../random_gen.cpp:19: error: ‘rand48’ is not a member of ‘boost::random’
../random_gen.cpp:19: error: expected ‘;’ before ‘rng’
../random_gen.cpp:20: error: ‘rng’ was not declared in this scope
../random_gen.cpp:21: error: ‘uniform_01’ is not a member of ‘boost::random’
../random_gen.cpp:21: error: expected primary-expression before ‘double’
../random_gen.cpp:21: error: expected ‘;’ before ‘double’
../random_gen.cpp:22: error: ‘udist’ was not declared in this scope
../random_gen.cpp:23: error: ‘normal_distribution’ is not a member of ‘boost::random’
../random_gen.cpp:23: error: expected primary-expression before ‘double’
../random_gen.cpp:23: error: expected ‘;’ before ‘double’
../random_gen.cpp:24: error: ‘ndist’ was not declared in this scope
make: *** [random_gen.o] Error 1
Thankyou mike
but when i am running this it gives
../random_gen.cpp: In function ‘int main()’:
../random_gen.cpp:19: error: ‘rand48’ is not a member of ‘boost::random’
../random_gen.cpp:19: error: expected ‘;’ before ‘rng’
../random_gen.cpp:20: error: ‘rng’ was not declared in this scope
../random_gen.cpp:21: error: ‘uniform_01’ is not a member of ‘boost::random’
../random_gen.cpp:21: error: expected primary-expression before ‘double’
../random_gen.cpp:21: error: expected ‘;’ before ‘double’
../random_gen.cpp:22: error: ‘udist’ was not declared in this scope
../random_gen.cpp:23: error: ‘normal_distribution’ is not a member of ‘boost::random’
../random_gen.cpp:23: error: expected primary-expression before ‘double’
../random_gen.cpp:23: error: expected ‘;’ before ‘double’
../random_gen.cpp:24: error: ‘ndist’ was not declared in this scope
make: *** [random_gen.o] Error 1
I correct this. Thanks once again
code is
#include <boost/random/linear_congruential.hpp>
#include <boost/random/uniform_01.hpp>
#include <boost/random/normal_distribution.hpp>
#include <iostream>
#include <ctime>
using namespace std;
using namespace boost;
int main() {
rand48 rng = rand48((unsigned int)time(NULL));
std::cout << " This is a random number: " << rng() << std::endl;
uniform_01<double> udist;
std::cout << " This is a uniformly distributed 'double' value in range [0,1]: " << udist(rng) << std::endl;
normal_distribution<double> ndist(0.5, 0.25);
std::cout << " This is a normally distributed 'double' value with mean 0.5 and std-dev 0.25: " << ndist(rng) << std::endl;
return 0;
};
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.