Chapter 7.1 ran.h
decrignis
11-12-2009, 03:06 PM
Hi - I am implementing the algorithm of ran.h (page342) in another programming language. I would like to validate
my version of the algorithm by comparing it with the C++ version.
Could somebody be so kind to give me the output of
10 calls of myran.doub with a starting seed of 17?
Then if I get the same sequence on my machine I passed the test :)
Thanks for helping me validate the code,
and best regards
davekw7x
11-12-2009, 03:22 PM
...
10 calls of myran.doub with a starting seed of 17?
...
#include "../code/nr3.h"
#include "../code/ran.h"
int main()
{
Int seed = 17;
Int n = 10;
cout << "Initializing ran1 with seed = " << seed << endl;
cout << "The first " << n << " values from ran1.doub()" << endl;
Ran r1(seed);
cout << fixed << setprecision(15);
for (Int i = 0; i < n; i++) {
cout << setw(23) << r1.doub() << endl;
}
cout << endl;
cout << "Initializing ran2 with seed = " << seed << endl;
cout << "The first " << n << " values from ran2.int64():" << endl;
Ran r2(seed);
for (Int i = 0; i < 10; i++) {
cout << setw(23) << r2.int64() << endl;
}
cout << endl;
return 0;
}
Output:
Initializing ran1 with seed = 17
The first 10 values from ran1.doub()
0.014634144665917
0.405368789415652
0.883352461356882
0.923735089582023
0.268071634315548
0.084861012842019
0.384621084061685
0.754996997475338
0.008140800673717
0.438715622850155
Initializing ran2 with seed = 17
The first 10 values from ran2.int64():
269952321389814056
7477734313819993120
16294976781531816119
17039904789424739738
4945048831639962635
1565409385732501729
7095006703038622919
13927236388846696772
150171266583137103
8092874815854888167
Regards,
Dave
decrignis
11-12-2009, 03:33 PM
Hi Dave - thank you very much - this agrees
very well with my output below!
Therefore I am satisfied that I validated
the code properly - in fact I'll add the option
of int64 output too :)
Thanks again!
0.014634144665917075
0.405368789415651964
0.883352461356882390
0.923735089582022773
0.268071634315547647
0.084861012842018871
0.384621084061684548
0.754996997475337994
0.008140800673716853
0.438715622850154807