GNU Octave  6.2.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-2021 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 
74 namespace octave
75 {
76  // Mersenne Twister.
77 
78  extern void init_mersenne_twister (void);
79  extern void init_mersenne_twister (const uint32_t seed);
80  extern void init_mersenne_twister (const uint32_t *init_key,
81  const int key_length);
82 
83  extern void set_mersenne_twister_state (const uint32_t *save);
84  extern void get_mersenne_twister_state (uint32_t *save);
85 
86  template <typename T> T rand_uniform (void);
87  template <typename T> T rand_normal (void);
88  template <typename T> T rand_exponential (void);
89 
90  template <typename T> void rand_uniform (octave_idx_type n, T *p);
91  template <typename T> void rand_normal (octave_idx_type n, T *p);
92  template <typename T> void rand_exponential (octave_idx_type n, T *p);
93 
94  template <> double rand_uniform<double> (void);
95  template <> double rand_normal<double> (void);
96  template <> double rand_exponential<double> (void);
97 
98  template <> float rand_uniform<float> (void);
99  template <> float rand_normal<float> (void);
100  template <> float rand_exponential<float> (void);
101 
102  template <> void
104 
105  template <> void
107 
108  template <> void
110 
111  template <> void
113 
114  template <> void
116 
117  template <> void
119 }
120 
121 #endif
octave_idx_type n
Definition: mx-inlines.cc:753
double rand_normal< double >(void)
Definition: randmtzig.cc:568
void set_mersenne_twister_state(const uint32_t *save)
Definition: randmtzig.cc:294
float rand_normal< float >(void)
Definition: randmtzig.cc:770
double rand_exponential< double >(void)
Definition: randmtzig.cc:632
float rand_exponential< float >(void)
Definition: randmtzig.cc:810
void init_mersenne_twister(const uint32_t s)
Definition: randmtzig.cc:197
float rand_uniform< float >(void)
Definition: randmtzig.cc:422
void rand_exponential(octave_idx_type n, double *p)
Definition: randmtzig.cc:668
void rand_normal(octave_idx_type n, double *p)
Definition: randmtzig.cc:663
void rand_uniform(octave_idx_type n, float *p)
Definition: randmtzig.cc:836
void get_mersenne_twister_state(uint32_t *save)
Definition: randmtzig.cc:301
double rand_uniform< double >(void)
Definition: randmtzig.cc:414