Stxxl  1.4.0
common/test_random.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  common/test_random.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright © 2007, 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00007  *
00008  *  Distributed under the Boost Software License, Version 1.0.
00009  *  (See accompanying file LICENSE_1_0.txt or copy at
00010  *  http://www.boost.org/LICENSE_1_0.txt)
00011  **************************************************************************/
00012 
00013 #include <iostream>
00014 #include <cassert>
00015 #include <stxxl/random>
00016 
00017 int main()
00018 {
00019     //stxxl::set_seed(42);
00020     std::cout << "seed = " << stxxl::get_next_seed() << std::endl;
00021 
00022     stxxl::srandom_number32(stxxl::get_next_seed());
00023 #ifndef BOOST_MSVC
00024     srand48(time(NULL));
00025 #endif
00026     stxxl::random_number32 random_number32;
00027     stxxl::random_number32_r random_number32_r;
00028     stxxl::random_uniform_fast random_uniform_fast;
00029     stxxl::random_uniform_slow random_uniform_slow;
00030     stxxl::random_number<> random_number_fast;
00031     stxxl::random_number<stxxl::random_uniform_slow> random_number_slow;
00032     stxxl::random_number64 random_number64;
00033 
00034     for (int i = 0; i < 3; ++i) {
00035 #ifndef BOOST_MSVC
00036         std::cout << "d48 " << drand48() << std::endl;
00037 #endif
00038         std::cout << "r32 " << random_number32() << std::endl;
00039         std::cout << "r3r " << random_number32_r() << std::endl;
00040         std::cout << "ruf " << random_uniform_fast() << std::endl;
00041         std::cout << "rus " << random_uniform_slow() << std::endl;
00042         std::cout << "rnf " << random_number_fast(42) << std::endl;
00043         std::cout << "rns " << random_number_slow(42) << std::endl;
00044         std::cout << "r64 " << random_number64() << std::endl;
00045         std::cout << std::endl;
00046     }
00047 
00048     stxxl::set_seed(42);
00049     assert(stxxl::get_next_seed() == 42);
00050     assert(stxxl::get_next_seed() != 42);
00051 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines