Vaucanson 1.4
|
00001 // random.hh: this file is part of the Vaucanson project. 00002 // 00003 // Vaucanson, a generic library for finite state machines. 00004 // 00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008 The Vaucanson Group. 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // The complete GNU General Public Licence Notice can be found as the 00013 // `COPYING' file in the root directory. 00014 // 00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00016 // 00017 #ifndef VCSN_MISC_RANDOM_HH 00018 # define VCSN_MISC_RANDOM_HH 00019 00025 # include <vaucanson/algebra/implementation/letter/range.hh> 00026 # include <vaucanson/algebra/implementation/semiring/q_number.hh> 00027 00028 namespace vcsn { 00029 namespace misc { 00030 00032 namespace random { 00033 00036 00037 template<typename T> 00038 T generate (); 00039 00044 template<typename T> 00045 T generate (T min, T max); 00046 00047 00049 template<> 00050 char generate<char> (); 00051 00053 template<> 00054 char generate<char> (char min, char max); 00055 00057 char generate_letter (); 00058 00060 char generate_digit (); 00061 00063 template<> 00064 bool generate<bool> (); 00065 00067 template<> 00068 int generate<int> (); 00069 00071 template<> 00072 int generate<int> (int min, int max); 00073 00075 template<> 00076 unsigned generate<unsigned> (); 00077 00079 template<> 00080 unsigned generate<unsigned> (unsigned min, unsigned max); 00081 00083 template<> 00084 float generate<float> (); 00085 00087 template<> 00088 float generate<float> (float min, float max); 00089 00091 template<> 00092 double generate<double> (); 00093 00095 template<> 00096 double generate<double> (double min, double max); 00097 00099 template <class IteratorValueType, class InputIterator, class OutputIterator> 00100 void sample_n (const IteratorValueType&, InputIterator first, InputIterator end, 00101 OutputIterator out, unsigned n); 00102 00104 template<> 00105 vcsn::algebra::RationalNumber generate<vcsn::algebra::RationalNumber> (); 00106 00115 template<> 00116 vcsn::algebra::RationalNumber 00117 generate<vcsn::algebra::RationalNumber> 00118 (const vcsn::algebra::RationalNumber min, 00119 const vcsn::algebra::RationalNumber max); 00120 00122 # define DECLARE_PAIR_SPECIALIZATION(TYPE1, TYPE2) \ 00123 template <> \ 00124 std::pair<TYPE1, TYPE2> generate<std::pair<TYPE1, TYPE2> >() 00125 00126 DECLARE_PAIR_SPECIALIZATION(char, char); 00127 DECLARE_PAIR_SPECIALIZATION(char, int); 00128 DECLARE_PAIR_SPECIALIZATION(int, int); 00129 DECLARE_PAIR_SPECIALIZATION(int, char); 00130 00131 # undef DECLARE_PAIR_SPECIALIZATION 00132 00134 00135 typedef 00136 vcsn::algebra::static_char_interval<'a', 'z'> 00137 small_alpha_interval_t; 00138 00139 typedef 00140 vcsn::algebra::static_ranged<char, small_alpha_interval_t> 00141 small_alpha_letter_t; 00142 00144 template <> 00145 small_alpha_letter_t 00146 generate<small_alpha_letter_t> (); 00151 } 00152 } // end of namespace misc. 00153 } // end of namespace vcsn. 00154 00155 00156 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB 00157 # include <vaucanson/misc/random.hxx> 00158 # endif // VCSN_USE_INTERFACE_ONLY 00159 00160 00161 #endif // ! VCSN_MISC_RANDOM_HH