random.cpp

来自「A C++ class library for scientific compu」· C++ 代码 · 共 55 行

CPP
55
字号
/***************************************************************************** * random.cpp        Blitz++ random numbers example */#include <random/uniform.h>#include <blitz/numinquire.h>#include <time.h>#include <iostream>#include <iomanip>using namespace ranlib;using namespace blitz;// 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#endiftemplate<typename T>void printRandoms(){  Uniform<T> x;  //x.seed((unsigned int)time(0));  x.seed(5);  int N=5;  for (int i = 0; i < N; ++i)     cout << setprecision(digits10(T())) << LD_HACK(x.random()) << endl;  cout << endl;}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;  printRandoms<float>();  cout << "Some random doubles: " << endl;  printRandoms<double>();  cout << "Some random long doubles: " << endl;  printRandoms<long double>();  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?