Please i am trying to solve this problem:
How to generate an exponential r.v. with parameter lambda from U(0,1)? Show
all your calculations. Write a short piece of C or C++ code to generate 1000 exponential r.v. from your equation, using lambda=85. What is the mean and variance of the 1000 random variables you have generated? Do they agree with the expected value and the variance of
an exponential r.v. with lambda=85?
my code so far is below. I want it to display the result in an array and be able to send the output to an excel file. I also noticed that my variance is not correct. can someone help me. the formula i am using is x = - 1/lambda*log(u)
do {
u = rand() / ((float)RAND_MAX+1);
x = (-(log(u)/lambda));
i++;
cout << x << " \n";
sum =sum + x;
mean = (sum/1000);
var = var + pow((x - mean),2);
}
while (i<1000);