Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
uniform.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/random/uniform.hh
11 /// @brief Uniform random number generator
12 /// @author Sergey Lyskov (Sergey.Lyskov@jhu.edu)
13 ///
14 /// @remarks
15 /// @li -
16 
17 
18 #ifndef INCLUDED_numeric_random_uniform_hh
19 #define INCLUDED_numeric_random_uniform_hh
20 
22 
23 // Utility headers
25 
26 // C++ headers
27 #include <iostream>
28 #include <string>
29 #include <cstdlib> //required by GCC 4.3.2
30 
31 #include <assert.h>
32 
33 namespace numeric {
34 namespace random {
35 
36 
37 /// @brief Uniform random number generator
39 {
40 public:
42 
43  virtual ~uniform_RG() {}
44 
45  virtual void setSeed(int const seed) = 0;
46 
47  virtual void setSeed(std::string const & seed) = 0; //< some generator take more than int to init
48 
49  virtual int getSeed() = 0;
50 
51  virtual double getRandom() = 0;
52 
53  virtual void saveState(std::ostream & out) = 0;
54 
55  virtual void restoreState(std::istream & in) = 0;
56 
57 }; // uniform_RG
58 
59 
60 /// @brief Generator based on rand() < clib > function.
61 class standard_RG : public uniform_RG
62 {
63 public:
64 
65  inline standard_RG() {}
66 
67  inline virtual ~standard_RG() {}
68 
69  inline void setSeed(int const seed) { seed_ = seed; srand( seed_ ); }
70 
71  inline void setSeed(std::string const &) { assert( false ); } // Not implemented yet!
72 
73  inline int getSeed() { return seed_; }
74 
75  inline double getRandom() { return (double)rand() / (double)RAND_MAX; }
76 
77  virtual void saveState(std::ostream & /*out*/) { assert( false ); } // Not implemented yet!
78 
79  virtual void restoreState(std::istream & /*in*/) { assert( false ); } // Not implemented yet!
80 
81 private:
82  int seed_;
83 
84 }; // standard_RG
85 
86 
87 } // namespace random
88 } // namespace numeric
89 
90 
91 #endif // INCLUDED_numeric_random_uniform_HH
virtual void restoreState(std::istream &in)=0
Uniform random number generator.
Definition: uniform.hh:38
virtual double getRandom()=0
virtual void setSeed(int const seed)=0
ReferenceCount base class – dispatch class.
Generator based on rand() < clib > function.
Definition: uniform.hh:61
virtual void restoreState(std::istream &)
Definition: uniform.hh:79
void setSeed(int const seed)
Definition: uniform.hh:69
Base class for reference-counted polymorphic classes.
virtual void saveState(std::ostream &out)=0
void setSeed(std::string const &)
Definition: uniform.hh:71
virtual void saveState(std::ostream &)
Definition: uniform.hh:77