Generated on Thu Jan 31 2019 20:56:39 for Gecode by doxygen 1.8.15
rnd.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2008
8  *
9  * Last modified:
10  * $Date: 2017-03-08 11:58:56 +0100 (Wed, 08 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15562 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <ctime>
39 
40 namespace Gecode {
41 
46  class Rnd : public SharedHandle {
47  private:
49  class IMP : public SharedHandle::Object {
50  public:
54  IMP(unsigned int s);
56  virtual ~IMP(void);
59  virtual SharedHandle::Object* copy(void) const;
60  };
62  void _seed(unsigned int s);
63  public:
66  Rnd(void);
69  Rnd(const Rnd& r);
72  Rnd& operator =(const Rnd& r);
75  ~Rnd(void);
78  Rnd(unsigned int s);
81  void seed(unsigned int s);
84  void time(void);
87  void hw(void);
89  unsigned int seed(void) const;
91  unsigned int operator ()(unsigned int n);
93  operator bool(void) const;
94  };
95 
96  forceinline unsigned int
97  Rnd::seed(void) const {
98  const IMP* i = static_cast<const IMP*>(object());
99  return i->rg.seed();
100  }
101  forceinline unsigned int
102  Rnd::operator ()(unsigned int n) {
103  IMP* i = static_cast<IMP*>(object());
104  return i->rg(n);
105  }
107  Rnd::operator bool(void) const {
108  return object() != NULL;
109  }
110 
111 }
112 
113 // STATISTICS: kernel-other
The shared handle.
Definition: core.hpp:79
unsigned int seed(void) const
Return current seed.
Definition: rnd.hpp:97
void time(void)
Set current seed based on time (initializes if needed)
Definition: rnd.cpp:82
Rnd(void)
Default constructor that does not initialize the generator.
Definition: rnd.cpp:64
Rnd & operator=(const Rnd &r)
Assignment operator.
Definition: rnd.cpp:71
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Template for linear congruential generators.
Definition: random.hpp:50
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:74
unsigned int operator()(unsigned int n)
Return a random integer from the interval [0..n)
Definition: rnd.hpp:102
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
void hw(void)
Set current seed to hardware-based random number (initializes if needed)
Definition: rnd.cpp:86
#define forceinline
Definition: config.hpp:173
The shared object.
Definition: core.hpp:88
Gecode toplevel namespace
Random number generator.
Definition: rnd.hpp:46
~Rnd(void)
Destructor.
Definition: rnd.cpp:75