]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/sort/example/boostrandomgen.cpp
update sources to v12.2.4
[ceph.git] / ceph / src / boost / libs / sort / example / boostrandomgen.cpp
index a34320cd01d36a12a50096d1925a3d9c0fd27ca2..75e455757a08952ea71c68ec6f8bf269649c2788 100644 (file)
@@ -1,69 +1,69 @@
-// a random number generator supporting different distributions.
-//
-//  Copyright Steven Ross 2009.
-//
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-//  See http://www.boost.org/libs/sort for library home page.
-
-#include <stdio.h>
-#include "stdlib.h"
-#include <fstream>
-#include <iostream>
-#include <vector>
-#include <string>
-#include <boost/random.hpp>
-
-using namespace std;
-using namespace boost;
-
-int main(int argc, const char ** argv) {
-  //Always seed with the same value, to get the same results
-  srand(1);
-  //defaults
-  int mod_shift = 32;
-  unsigned count = 1000000;
-  //Reading in user arguments
-  if (argc > 2)
-    count = atoi(argv[2]);
-  if (argc > 1)
-    mod_shift = atoi(argv[1]) - 1;
-  std::ofstream ofile;
-  ofile.open("input.txt", std::ios_base::out | std::ios_base::binary |
-             std::ios_base::trunc);
-  if (ofile.bad()) {
-    printf("could not open input.txt for writing!\n");
-    return 1;
-  }
-  int min_int = (numeric_limits<int>::min)();
-  int max_int = (numeric_limits<int>::max)();
-  if (mod_shift < 31 && mod_shift >= 0) {
-    max_int %= 1 << mod_shift;
-    if (-max_int > min_int)
-      min_int = -max_int;
-  }
-  std::vector<int> result;
-  result.resize(count);
-  mt19937 rng;
-  if (argc > 3 && (string(argv[3]) == "-normal")) {
-    normal_distribution<> everything(0, max_int/4);      
-    variate_generator<mt19937&,normal_distribution<> > gen(rng, everything);
-    generate(result.begin(), result.end(), gen);
-  }
-  else if (argc > 3 && (string(argv[3]) == "-lognormal")) {
-    lognormal_distribution<> everything(max_int/2, max_int/4);      
-    variate_generator<mt19937&,lognormal_distribution<> > gen(rng, everything);
-    generate(result.begin(), result.end(), gen);
-  }
-  else {
-    uniform_int<> everything(min_int, max_int);
-    variate_generator<mt19937&,uniform_int<> > gen(rng, everything);
-    generate(result.begin(), result.end(), gen);
-  }
-  ofile.write(reinterpret_cast<char *>(&(result[0])), result.size() * 
-              sizeof(int));
-  ofile.close();
-  return 0;
-}
+// a random number generator supporting different distributions.\r
+//\r
+//  Copyright Steven Ross 2009.\r
+//\r
+// Distributed under the Boost Software License, Version 1.0.\r
+//    (See accompanying file LICENSE_1_0.txt or copy at\r
+//          http://www.boost.org/LICENSE_1_0.txt)\r
+\r
+//  See http://www.boost.org/libs/sort for library home page.\r
+\r
+#include <stdio.h>\r
+#include "stdlib.h"\r
+#include <fstream>\r
+#include <iostream>\r
+#include <vector>\r
+#include <string>\r
+#include <boost/random.hpp>\r
+\r
+using namespace std;\r
+using namespace boost;\r
+\r
+int main(int argc, const char ** argv) {\r
+  //Always seed with the same value, to get the same results\r
+  srand(1);\r
+  //defaults\r
+  int mod_shift = 32;\r
+  unsigned count = 1000000;\r
+  //Reading in user arguments\r
+  if (argc > 2)\r
+    count = atoi(argv[2]);\r
+  if (argc > 1)\r
+    mod_shift = atoi(argv[1]) - 1;\r
+  std::ofstream ofile;\r
+  ofile.open("input.txt", std::ios_base::out | std::ios_base::binary |\r
+             std::ios_base::trunc);\r
+  if (ofile.bad()) {\r
+    printf("could not open input.txt for writing!\n");\r
+    return 1;\r
+  }\r
+  int min_int = (numeric_limits<int>::min)();\r
+  int max_int = (numeric_limits<int>::max)();\r
+  if (mod_shift < 31 && mod_shift >= 0) {\r
+    max_int %= 1 << mod_shift;\r
+    if (-max_int > min_int)\r
+      min_int = -max_int;\r
+  }\r
+  std::vector<int> result;\r
+  result.resize(count);\r
+  mt19937 rng;\r
+  if (argc > 3 && (string(argv[3]) == "-normal")) {\r
+    normal_distribution<> everything(0, max_int/4);      \r
+    variate_generator<mt19937&,normal_distribution<> > gen(rng, everything);\r
+    generate(result.begin(), result.end(), gen);\r
+  }\r
+  else if (argc > 3 && (string(argv[3]) == "-lognormal")) {\r
+    lognormal_distribution<> everything(max_int/2, max_int/4);      \r
+    variate_generator<mt19937&,lognormal_distribution<> > gen(rng, everything);\r
+    generate(result.begin(), result.end(), gen);\r
+  }\r
+  else {\r
+    uniform_int<> everything(min_int, max_int);\r
+    variate_generator<mt19937&,uniform_int<> > gen(rng, everything);\r
+    generate(result.begin(), result.end(), gen);\r
+  }\r
+  ofile.write(reinterpret_cast<char *>(&(result[0])), result.size() * \r
+              sizeof(int));\r
+  ofile.close();\r
+  return 0;\r
+}\r