#include <iostream> #include <cmath> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; double cls_random(double lambda) { double pV = 0.0; while(true) { pV = (double)rand()/(double)RAND_MAX; if (pV != 1) { break; } } pV = (-1.0/lambda)*log(1-pV); return pV; } int main() { int num = 50; double arr[500]; for(int i=0; i<100; i++) { for(int j = 0; j<5; j++) { arr[i*5+j] = cls_random(0.02); cout<<arr[i*5+j]<< ' '; } cout<<endl; } double tmp = 0 ; for(int i = 0; i<500; i++) tmp+=arr[i]; cout<<"tmp = "<<tmp/500<<endl; system("Pause"); return 0; }