VTK  9.1.0
vtkMersenneTwister.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMersenneTwister.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 =========================================================================*/
14 
15 /*
16  Copyright (C) 2001-2009 Makoto Matsumoto and Takuji Nishimura.
17  Copyright (C) 2009 Mutsuo Saito
18  All rights reserved.
19 
20  Redistribution and use in source and binary forms, with or without
21  modification, are permitted provided that the following conditions are
22  met:
23 
24  * Redistributions of source code must retain the above copyright
25  notice, this list of conditions and the following disclaimer.
26  * Redistributions in binary form must reproduce the above
27  copyright notice, this list of conditions and the following
28  disclaimer in the documentation and/or other materials provided
29  with the distribution.
30 
31  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43 
68 #ifndef vtkMersenneTwister_h
69 #define vtkMersenneTwister_h
70 
71 #include "vtkCommonCoreModule.h" // For export macro
72 #include "vtkRandomSequence.h"
73 
74 class vtkMersenneTwisterInternals;
75 
76 class VTKCOMMONCORE_EXPORT vtkMersenneTwister : public vtkRandomSequence
77 {
78 public:
79  typedef vtkTypeUInt32 SequenceId;
80 
82 
87  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
94  void Initialize(vtkTypeUInt32 seed) override { this->InitializeSequence(0, seed); }
95 
103  SequenceId InitializeNewSequence(vtkTypeUInt32 seed, int p = 521);
104 
111  void InitializeSequence(SequenceId id, vtkTypeUInt32 seed, int p = 521);
112 
117  virtual double GetValue(SequenceId id);
118 
123  double GetValue() override { return this->GetValue(0); }
124 
130  virtual void Next(SequenceId id);
131 
137  void Next() override { return this->Next(0); }
138 
139 protected:
142 
143  vtkMersenneTwisterInternals* Internal;
144 
145 private:
146  vtkMersenneTwister(const vtkMersenneTwister&) = delete;
147  void operator=(const vtkMersenneTwister&) = delete;
148 };
149 
150 #endif // #ifndef vtkMersenneTwister_h
a simple class to control print indentation
Definition: vtkIndent.h:34
Generator for Mersenne Twister pseudorandom numbers.
virtual void Next(SequenceId id)
Move to the next number in random sequence id.
vtkTypeUInt32 SequenceId
static vtkMersenneTwister * New()
Standard methods for instantiation, type information, and printing.
vtkMersenneTwisterInternals * Internal
void Next() override
Move to the next number in random sequence <0>.
void InitializeSequence(SequenceId id, vtkTypeUInt32 seed, int p=521)
Initialize a sequence as in InitializeNewSequence(), but additionally pass an id to associate with th...
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
virtual double GetValue(SequenceId id)
Current value.
double GetValue() override
Current value.
void Initialize(vtkTypeUInt32 seed) override
Satisfy general API of vtkRandomSequence superclass.
SequenceId InitializeNewSequence(vtkTypeUInt32 seed, int p=521)
Initialize a new Mersenne Twister sequence, given a) a seed and b) a Mersenne exponent (p s....
~vtkMersenneTwister() override
Generate a sequence of random numbers.