MathTL
|
00001 // -*- c++ -*- 00002 00003 // +--------------------------------------------------------------------+ 00004 // | This file is part of MathTL - the Mathematical Template Library | 00005 // | | 00006 // | Copyright (c) 2002-2009 | 00007 // | Thorsten Raasch, Manuel Werner | 00008 // +--------------------------------------------------------------------+ 00009 00010 #ifndef _MATHTL_RANDOM_H 00011 #define _MATHTL_RANDOM_H 00012 00013 #include <cmath> 00014 #include <cstdlib> 00015 #include <time.h> 00016 00017 namespace MathTL 00018 { 00022 double random_double(const double a = 0, const double b = 1) 00023 { 00024 return a + (b-a) * (double(rand())/RAND_MAX); 00025 } 00026 00030 int random_integer(const int a = 0, const int b = 1) 00031 { 00032 return (int) (floor) (a + (b-a+1) * (double(rand())/RAND_MAX)); 00033 } 00034 } 00035 00036 #endif