File indexing completed on 2024-09-29 06:26:38
0001 #include <fstream> 0002 #include <iostream> 0003 #include <math.h> 0004 0005 #include <gsl/gsl_randist.h> 0006 #include <gsl/gsl_rng.h> 0007 0008 int main() { 0009 std::string fileName = "out_1M_5pathes.bin"; 0010 int count = 1000000; 0011 int pathes = 5; 0012 0013 double delta = 0.25; 0014 int dt = 1; 0015 double sigma = std::pow(delta, 2) * dt; 0016 double path[pathes] = {0.0}; 0017 0018 std::ofstream ostrm(fileName, std::ios::binary); 0019 0020 // create a generator chosen by the environment variable GSL_RNG_TYPE 0021 gsl_rng_env_setup(); 0022 const gsl_rng_type* T = gsl_rng_default; 0023 gsl_rng* r = gsl_rng_alloc(T); 0024 gsl_rng_set(r, 12345); 0025 0026 // data 0027 for (int i = 0; i < count; ++i) { 0028 double x = i * dt; 0029 ostrm.write(reinterpret_cast<char*>(&x), sizeof(double)); 0030 0031 for (int p = 0; p < pathes; ++p) { 0032 path[p] += gsl_ran_gaussian(r, sigma); 0033 ostrm.write(reinterpret_cast<char*>(&path[p]), sizeof(double)); 0034 } 0035 } 0036 }