Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
rnd.cpp
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  * Mikael Lagerkvist <lagerkvist@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2008
9  * Mikael Lagerkvist, 2008
10  *
11  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <gecode/kernel.hh>
41 
42 namespace Gecode {
43 
44  Support::Mutex Rnd::IMP::m;
45 
47  Rnd::IMP::IMP(unsigned int s)
48  : rg(s) {}
49 
50  Rnd::IMP::~IMP(void) {}
51 
52  forceinline void
53  Rnd::_seed(unsigned int s) {
54  if (object() == NULL) {
55  object(new IMP(s));
56  } else {
57  static_cast<IMP*>(object())->seed(s);
58  }
59  }
60 
61  Rnd::Rnd(void) {}
62  Rnd::Rnd(unsigned int s) {
63  object(new IMP(s));
64  }
65  Rnd::Rnd(const Rnd& r)
66  : SharedHandle(r) {}
67  Rnd&
68  Rnd::operator =(const Rnd& r) {
69  (void) SharedHandle::operator =(r);
70  return *this;
71  }
72  Rnd::~Rnd(void) {}
73 
74  void
75  Rnd::seed(unsigned int s) {
76  _seed(s);
77  }
78  void
79  Rnd::time(void) {
80  _seed(static_cast<unsigned int>(::time(NULL)));
81  }
82  void
83  Rnd::hw(void) {
84  _seed(Support::hwrnd());
85  }
86 }
87 
88 // STATISTICS: kernel-other
The shared handle.
unsigned int seed(void) const
Return current seed.
Definition: rnd.hpp:124
#define forceinline
Definition: config.hpp:182
void time(void)
Set current seed based on time (initializes if needed)
Definition: rnd.cpp:79
Rnd(void)
Default constructor that does not initialize the generator.
Definition: rnd.cpp:61
Rnd & operator=(const Rnd &r)
Assignment operator.
Definition: rnd.cpp:68
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
void hw(void)
Set current seed to hardware-based random number (initializes if needed)
Definition: rnd.cpp:83
Gecode toplevel namespace
Random number generator.
Definition: rnd.hpp:46
~Rnd(void)
Destructor.
Definition: rnd.cpp:72
unsigned int hwrnd(void)
Return hardware generated random number.
Definition: hw-rnd.cpp:63