-
Notifications
You must be signed in to change notification settings - Fork 5
/
rndunif.cpp
53 lines (48 loc) · 1.22 KB
/
rndunif.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include "rndunif.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
// Constructor *********************************************************
/*RNDUNIF::RNDUNIF(double minval, double maxval)
{
MinValue = minval;
MaxValue = maxval;
DiffValue = MaxValue - MinValue;
Mean = 0.5 * (MinValue + MaxValue);
Var = DiffValue * DiffValue / 12.0;
}
*/
// output operator *****************************************************
ostream& operator<<(ostream& outp, RNDUNIF& gen)
{
outp << "RNDUNIF ]" << gen.MinValue << ", " << gen.MaxValue
<< "[, EX = " << gen.Mean << ", VarX = " << gen.Var;
return outp;
}
// main program for a demonstration of generator output ****************
//#ifdef SINGLE
int main()
{ srand(time(NULL));
double min, max;
int no;
cout << "min.? ";
cin >> min;
cout << "max.? ";
cin >> max;
cout << "no.? ";
cin >> no;
RNDUNIF RU(min, max);
cout << RU << ":" << endl;
for (int i = 0; i < no; i++)
{
printf("%6.3lf", RU.Rnd());
if (i % 10 == 9)
cout << endl;
else
cout << "\t";
}
return 0;
}
//#endif