INGOR
ytRNG.h
1/*
2 math/ytRNG.{h,c} : Random Number Generator
3 Copyright (C) 2018, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_RNG_H
37#define __YTLIB_RNG_H
38
39#if defined(USE_FUJITSU_FCC_SSL)
40
41#elif !defined(USE_DSFMT) && defined(USE_INTEL_MKL)
42#include <mkl_vsl.h>
43#else
44#include "ytRNG_dSFMT.h"
45#endif
46
60typedef struct {
61#if defined(USE_FUJITSU_FCC_SSL)
63 int ssl_dvrau4_seed;
65 double * ssl_dvrau4_work;
67 int ssl_dvrau4_work_size;
68
70 int ssl_dvran3_seed;
72 double * ssl_dvran3_work;
74 int ssl_dvran3_work_size;
75#elif !defined(USE_DSFMT) && defined(USE_INTEL_MKL)
76 VSLStreamStatePtr mkl_vsl_stream;
77#else
78 ytRNG_dSFMT * dsfmt;
79 double work[DSFMT_N64];
80#endif
81} ytRNG;
82
84void ytRNG_delete(ytRNG * rng);
85void ytRNG_setSeed(ytRNG * rng, int seed);
86void ytRNG_normal(ytRNG * rng, double * ar, int n, double mean, double sigma);
87void ytRNG_uniform(ytRNG * rng, double * ar, int n, double min, double max);
88void ytRNG_integer(ytRNG * rng, int * ar, int n, int min, int max);
89void ytRNG_perm(ytRNG * rng, int * ar, int n);
90void ytRNG_shuffle(ytRNG * rng, int * ar, int n);
91int ytRNG_debug(int argc, char * argv[]);
92
93#endif /* __YTLIB_RNG_H */
Definition: ytRNG_dSFMT.h:220
Structure for encapsulating the random number generator.
Definition: ytRNG.h:60
void ytRNG_integer(ytRNG *rng, int *ar, int n, int min, int max)
Generates integer random numbers.
Definition: ytRNG.c:236
void ytRNG_delete(ytRNG *rng)
Releases the resources allocated for the ytRNG instance.
Definition: ytRNG.c:91
void ytRNG_setSeed(ytRNG *rng, int seed)
Initializes the random number generator.
Definition: ytRNG.c:124
void ytRNG_uniform(ytRNG *rng, double *ar, int n, double min, double max)
Generates the normally distributed random numbers.
Definition: ytRNG.c:193
void ytRNG_normal(ytRNG *rng, double *ar, int n, double mean, double sigma)
Generates the normally distributed random numbers.
Definition: ytRNG.c:160
ytRNG * ytRNG_new()
Generates an ytRNG instance.
Definition: ytRNG.c:62
void ytRNG_shuffle(ytRNG *rng, int *ar, int n)
Shuffles the elements of the integer array.
Definition: ytRNG.c:293
void ytRNG_perm(ytRNG *rng, int *ar, int n)
Generates an integer random permuation vector.
Definition: ytRNG.c:271