GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
randmtzig.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2006-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 /*
27  A C-program for MT19937, with initialization improved 2002/2/10.
28  Coded by Takuji Nishimura and Makoto Matsumoto.
29  This is a faster version by taking Shawn Cokus's optimization,
30  Matthe Bellew's simplification, Isaku Wada's real version.
31  David Bateman added normal and exponential distributions following
32  Marsaglia and Tang's Ziggurat algorithm.
33 
34  Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
35  Copyright (C) 2004, David Bateman
36  All rights reserved.
37 
38  Redistribution and use in source and binary forms, with or without
39  modification, are permitted provided that the following conditions
40  are met:
41 
42  1. Redistributions of source code must retain the above copyright
43  notice, this list of conditions and the following disclaimer.
44 
45  2. Redistributions in binary form must reproduce the above copyright
46  notice, this list of conditions and the following disclaimer in the
47  documentation and/or other materials provided with the distribution.
48 
49  3. The names of its contributors may not be used to endorse or promote
50  products derived from this software without specific prior written
51  permission.
52 
53  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
57  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 
65 */
66 
67 #if ! defined (octave_randmtzig_h)
68 #define octave_randmtzig_h 1
69 
70 #include "octave-config.h"
71 
72 #define MT_N 624
73 
75 
76 // Mersenne Twister.
77 
78 extern OCTAVE_API void init_mersenne_twister ();
79 extern OCTAVE_API void init_mersenne_twister (const uint32_t seed);
80 extern OCTAVE_API void init_mersenne_twister (const uint32_t *init_key,
81  const int key_length);
82 
83 extern OCTAVE_API void set_mersenne_twister_state (const uint32_t *save);
84 extern OCTAVE_API void get_mersenne_twister_state (uint32_t *save);
85 
86 template <typename T> OCTAVE_API T rand_uniform ();
87 template <typename T> OCTAVE_API T rand_normal ();
88 template <typename T> OCTAVE_API T rand_exponential ();
89 
90 template <typename T> OCTAVE_API void rand_uniform (octave_idx_type n, T *p);
91 template <typename T> OCTAVE_API void rand_normal (octave_idx_type n, T *p);
92 template <typename T> OCTAVE_API void
94 
95 template <> OCTAVE_API double rand_uniform<double> ();
96 template <> OCTAVE_API double rand_normal<double> ();
97 template <> OCTAVE_API double rand_exponential<double> ();
98 
99 template <> OCTAVE_API float rand_uniform<float> ();
100 template <> OCTAVE_API float rand_normal<float> ();
101 template <> OCTAVE_API float rand_exponential<float> ();
102 
103 template <> OCTAVE_API void
105 
106 template <> OCTAVE_API void
108 
109 template <> OCTAVE_API void
111 
112 template <> OCTAVE_API void
114 
115 template <> OCTAVE_API void
117 
118 template <> OCTAVE_API void
120 
121 OCTAVE_END_NAMESPACE(octave)
122 
123 #endif
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define OCTAVE_API
Definition: main.cc:55
octave_idx_type n
Definition: mx-inlines.cc:761
void get_mersenne_twister_state(uint32_t *save)
Definition: randmtzig.cc:323
double rand_uniform< double >()
Definition: randmtzig.cc:442
void set_mersenne_twister_state(const uint32_t *save)
Definition: randmtzig.cc:315
void init_mersenne_twister()
Definition: randmtzig.cc:263
double rand_normal< double >()
Definition: randmtzig.cc:599
float rand_normal< float >()
Definition: randmtzig.cc:806
float rand_exponential< float >()
Definition: randmtzig.cc:848
T rand_exponential()
T rand_uniform()
double rand_exponential< double >()
Definition: randmtzig.cc:665
T rand_normal()
float rand_uniform< float >()
Definition: randmtzig.cc:450