random.cpp | random.cpp | |||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
#include <random/uniform.h> | #include <random/uniform.h> | |||
#include <blitz/numinquire.h> | #include <blitz/numinquire.h> | |||
#include <time.h> | #include <time.h> | |||
#include <iostream> | #include <iostream> | |||
#include <iomanip> | #include <iomanip> | |||
using namespace ranlib; | using namespace ranlib; | |||
using namespace blitz; | using namespace blitz; | |||
template<class T> | // workaround for broken streams in Compaq cxx, can't handle long double | |||
#if defined(__DECCXX) | ||||
#define LD_HACK(x) static_cast<double>(x) | ||||
#else | ||||
#define LD_HACK(x) x | ||||
#endif | ||||
template<typename T> | ||||
void printRandoms() | void printRandoms() | |||
{ | { | |||
Uniform<T> x; | Uniform<T> x; | |||
//x.seed((unsigned int)time(0)); | //x.seed((unsigned int)time(0)); | |||
x.seed(5); | x.seed(5); | |||
int N=5; | int N=5; | |||
for (int i = 0; i < N; ++i) | for (int i = 0; i < N; ++i) | |||
cout << setprecision(digits10(T())) << x.random() << endl; | cout << setprecision(digits10(T())) << LD_HACK(x.random()) << endl; | |||
cout << endl; | cout << endl; | |||
} | } | |||
int main() | int main() | |||
{ | { | |||
// test get/set state interface | ||||
Uniform<double> x; | ||||
Uniform<double>::T_state S = x.getState(); | ||||
x.setState(S); | ||||
std::string str = x.getStateString(); | ||||
x.setState(str); | ||||
cout << "Some random float: " << endl; | cout << "Some random float: " << endl; | |||
printRandoms<float>(); | printRandoms<float>(); | |||
cout << "Some random doubles: " << endl; | cout << "Some random doubles: " << endl; | |||
printRandoms<double>(); | printRandoms<double>(); | |||
cout << "Some random long doubles: " << endl; | cout << "Some random long doubles: " << endl; | |||
printRandoms<long double>(); | printRandoms<long double>(); | |||
return 0; | return 0; | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 16 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |