Prefixed each each exported symbol with SCM_API.
[bpt/guile.git] / libguile / random.h
CommitLineData
e7a72986
MD
1/* classes: h_files */
2
8c494e99
DH
3#ifndef SCM_RANDOM_H
4#define SCM_RANDOM_H
5
6/* Copyright (C) 1999,2000,2001 Free Software Foundation, Inc.
7 *
e7a72986
MD
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
8c494e99 12 *
e7a72986
MD
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
8c494e99 17 *
e7a72986
MD
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
22 *
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
25 *
26 * The exception is that, if you link the GUILE library with other files
27 * to produce an executable, this does not by itself cause the
28 * resulting executable to be covered by the GNU General Public License.
29 * Your use of that executable is in no way restricted on account of
30 * linking the GUILE library code into it.
31 *
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
34 *
35 * This exception applies only to the code released by the
36 * Free Software Foundation under the name GUILE. If you copy
37 * code from other Free Software Foundation releases into a copy of
38 * GUILE, as the General Public License permits, the exception does
39 * not apply to the code that you add in this way. To avoid misleading
40 * anyone as to the status of such modified files, you must delete
41 * this exception notice from them.
42 *
43 * If you write modifications of your own for GUILE, it is your choice
44 * whether to permit this exception to apply to your modifications.
45 * If you do not wish that, delete this exception notice. */
d3a6bc94 46
e7a72986
MD
47\f
48
49#include "libguile/__scm.h"
50
51\f
52/*
53 * A plugin interface for RNGs
54 *
55 * Using this interface, it is possible for the application to tell
56 * libguile to use a different RNG. This is desirable if it is
57 * necessary to use the same RNG everywhere in the application in
58 * order to prevent interference, if the application uses RNG
59 * hardware, or if the application has special demands on the RNG.
60 *
61 * Look how the default generator is "plugged in" in scm_init_random().
62 */
63
92c2555f 64typedef struct scm_t_rstate {
e7a72986
MD
65 int reserved0;
66 double reserved1;
67 /* Custom fields follow here */
92c2555f 68} scm_t_rstate;
e7a72986 69
92c2555f 70typedef struct scm_t_rng {
e7a72986 71 size_t rstate_size; /* size of random state */
92c2555f
MV
72 unsigned long (*random_bits) (scm_t_rstate *state); /* gives 32 random bits */
73 void (*init_rstate) (scm_t_rstate *state, char *seed, int n);
74 scm_t_rstate *(*copy_rstate) (scm_t_rstate *state);
75} scm_t_rng;
e7a72986 76
33b001fd 77SCM_API scm_t_rng scm_the_rng;
e7a72986
MD
78
79\f
80/*
81 * Default RNG
82 */
92c2555f
MV
83typedef struct scm_t_i_rstate {
84 scm_t_rstate rstate;
e7a72986
MD
85 unsigned long w;
86 unsigned long c;
92c2555f 87} scm_t_i_rstate;
e7a72986 88
33b001fd
MV
89SCM_API unsigned long scm_i_uniform32 (scm_t_i_rstate *);
90SCM_API void scm_i_init_rstate (scm_t_i_rstate *, char *seed, int n);
91SCM_API scm_t_i_rstate *scm_i_copy_rstate (scm_t_i_rstate *);
e7a72986
MD
92
93\f
94/*
95 * Random number library functions
96 */
33b001fd
MV
97SCM_API scm_t_rstate *scm_c_make_rstate (char *, int);
98SCM_API scm_t_rstate *scm_c_default_rstate (void);
9b741bb6 99#define scm_c_uniform32(RSTATE) scm_the_rng.random_bits (RSTATE)
33b001fd
MV
100SCM_API double scm_c_uniform01 (scm_t_rstate *);
101SCM_API double scm_c_normal01 (scm_t_rstate *);
102SCM_API double scm_c_exp1 (scm_t_rstate *);
103SCM_API unsigned long scm_c_random (scm_t_rstate *, unsigned long m);
104SCM_API SCM scm_c_random_bignum (scm_t_rstate *, SCM m);
e7a72986
MD
105
106\f
107/*
108 * Scheme level interface
109 */
33b001fd 110SCM_API scm_t_bits scm_tc16_rstate;
e841c3e0 111#define SCM_RSTATEP(obj) SCM_TYP16_PREDICATE (scm_tc16_rstate, obj)
92c2555f 112#define SCM_RSTATE(obj) ((scm_t_rstate *) SCM_CELL_WORD_1 (obj))
e7a72986 113
33b001fd
MV
114SCM_API unsigned char scm_masktab[256];
115
116SCM_API SCM scm_var_random_state;
117SCM_API SCM scm_random (SCM n, SCM state);
118SCM_API SCM scm_copy_random_state (SCM state);
119SCM_API SCM scm_seed_to_random_state (SCM seed);
120SCM_API SCM scm_random_uniform (SCM state);
121SCM_API SCM scm_random_solid_sphere_x (SCM v, SCM state);
122SCM_API SCM scm_random_hollow_sphere_x (SCM v, SCM state);
123SCM_API SCM scm_random_normal (SCM state);
124SCM_API SCM scm_random_normal_vector_x (SCM v, SCM state);
125SCM_API SCM scm_random_exp (SCM state);
126SCM_API void scm_init_random (void);
e7a72986 127
8c494e99 128#endif /* SCM_RANDOM_H */
89e00824
ML
129
130/*
131 Local Variables:
132 c-file-style: "gnu"
133 End:
134*/