I am facing problem to generate random number in real value. Let us consider l=0.045, so i need the random value between 0.0025 to 0.040. Can anybody help me how to write down programming code in c++ to determine real value generation of random number?
#include <iostream>
#include <random>
#include <ctime>
int main()
{
// define a random number engine, seeded with a true random value
// http://en.cppreference.com/w/cpp/numeric/random
// http://en.cppreference.com/w/cpp/numeric/random/random_device
std::default_random_engine rng( std::random_device{}() ) ;
// if a a true random value is not available, seed it with a reasonably random value
// std::default_random_engine rng( std::time(nullptr) ) ;
// optional: warm up the engine
rng.discard(1000) ;
// define the required random number distribution. for instance:
// http://en.cppreference.com/w/cpp/numeric/random/normal_distribution
std::normal_distribution<double> normal_5_2( 50.0, 2.0 ) ; // mean 50.0, standard deviation 2.0
// generate random numbers according to the distribution
for( int i = 0 ; i < 10 ; ++i ) std::cout << normal_5_2(rng) << ' ' ;
std::cout << '\n' ;
// define the required random number distribution. for instance:
std::uniform_real_distribution<double> uniform_10_99( 10.0, 99.0 ) ; // distributed in [ 10.0, 99.0 ]
// generate random numbers according to the distribution
for( int i = 0 ; i < 10 ; ++i ) std::cout << uniform_10_99(rng) << ' ' ;
std::cout << '\n' ;
}