Please help write a program in C Write a program to generate

Please help write a program in C++

Write a program to generate 2,000,000 floating-point random numbers that uniformly distribute in (0, 10). Generate 2,000,000 normally distributed random numbers using the Box-Muller\'s method. Make a histogram for the numbers generated above.

Solution

1)

#include <iostream>
#include <random>
using namespace std;

double rdnm (double p, double q)
{
static std::default_random_engine generator;
std::uniform_real_distribution<double> distribution (p,q);
return distribution(generator);
}

int main()
{
const int np=5;

double amin =0;
double amax=10;
double au[np];

for (int i=0;i<np;i++)
{
au[i]=rdnm(amin,amax);
cout<<au[i]<<endl;
}
}

2)

#include <iostream>
#include <random>

int main()
{
const int nrolls=10 // number of experiments
const int nstars=10; // maximum number of stars to distribute

std::default_random_engine generator;
std::normal_distribution<double> distribution(5.0,2.0);

int p[10]={};

for (int i=0; i<nrolls; ++i) {
double number = distribution(generator);
if ((number>=0.0)&&(number<10.0)) ++p[int(number)];
}

std::cout << \"normal_distribution (5.0,2.0):\" << std::endl;

for (int i=0; i<10; ++i) {
std::cout << i << \"-\" << (i+1) << \": \";
std::cout << std::string(p[i]*nstars/nrolls,\'*\') << std::endl;
}

return 0;
}

Please help write a program in C++ Write a program to generate 2,000,000 floating-point random numbers that uniformly distribute in (0, 10). Generate 2,000,000
Please help write a program in C++ Write a program to generate 2,000,000 floating-point random numbers that uniformly distribute in (0, 10). Generate 2,000,000

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site