(gh_set_substr): Made src const.
[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 *
73be1d9e
MV
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
8c494e99 12 *
73be1d9e 13 * This library is distributed in the hope that it will be useful,
e7a72986 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
8c494e99 17 *
73be1d9e
MV
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
d3a6bc94 22
e7a72986
MD
23\f
24
25#include "libguile/__scm.h"
26
27\f
28/*
29 * A plugin interface for RNGs
30 *
31 * Using this interface, it is possible for the application to tell
32 * libguile to use a different RNG. This is desirable if it is
33 * necessary to use the same RNG everywhere in the application in
34 * order to prevent interference, if the application uses RNG
35 * hardware, or if the application has special demands on the RNG.
36 *
37 * Look how the default generator is "plugged in" in scm_init_random().
38 */
39
92c2555f 40typedef struct scm_t_rstate {
e7a72986
MD
41 int reserved0;
42 double reserved1;
43 /* Custom fields follow here */
92c2555f 44} scm_t_rstate;
e7a72986 45
92c2555f 46typedef struct scm_t_rng {
e7a72986 47 size_t rstate_size; /* size of random state */
92c2555f
MV
48 unsigned long (*random_bits) (scm_t_rstate *state); /* gives 32 random bits */
49 void (*init_rstate) (scm_t_rstate *state, char *seed, int n);
50 scm_t_rstate *(*copy_rstate) (scm_t_rstate *state);
51} scm_t_rng;
e7a72986 52
33b001fd 53SCM_API scm_t_rng scm_the_rng;
e7a72986
MD
54
55\f
56/*
57 * Default RNG
58 */
92c2555f
MV
59typedef struct scm_t_i_rstate {
60 scm_t_rstate rstate;
e7a72986
MD
61 unsigned long w;
62 unsigned long c;
92c2555f 63} scm_t_i_rstate;
e7a72986 64
33b001fd
MV
65SCM_API unsigned long scm_i_uniform32 (scm_t_i_rstate *);
66SCM_API void scm_i_init_rstate (scm_t_i_rstate *, char *seed, int n);
67SCM_API scm_t_i_rstate *scm_i_copy_rstate (scm_t_i_rstate *);
e7a72986
MD
68
69\f
70/*
71 * Random number library functions
72 */
33b001fd
MV
73SCM_API scm_t_rstate *scm_c_make_rstate (char *, int);
74SCM_API scm_t_rstate *scm_c_default_rstate (void);
9b741bb6 75#define scm_c_uniform32(RSTATE) scm_the_rng.random_bits (RSTATE)
33b001fd
MV
76SCM_API double scm_c_uniform01 (scm_t_rstate *);
77SCM_API double scm_c_normal01 (scm_t_rstate *);
78SCM_API double scm_c_exp1 (scm_t_rstate *);
79SCM_API unsigned long scm_c_random (scm_t_rstate *, unsigned long m);
80SCM_API SCM scm_c_random_bignum (scm_t_rstate *, SCM m);
e7a72986
MD
81
82\f
83/*
84 * Scheme level interface
85 */
33b001fd 86SCM_API scm_t_bits scm_tc16_rstate;
f5710d53
MV
87#define SCM_RSTATEP(obj) SCM_SMOB_PREDICATE (scm_tc16_rstate, obj)
88#define SCM_RSTATE(obj) ((scm_t_rstate *) SCM_SMOB_DATA (obj))
e7a72986 89
33b001fd
MV
90SCM_API unsigned char scm_masktab[256];
91
92SCM_API SCM scm_var_random_state;
93SCM_API SCM scm_random (SCM n, SCM state);
94SCM_API SCM scm_copy_random_state (SCM state);
95SCM_API SCM scm_seed_to_random_state (SCM seed);
96SCM_API SCM scm_random_uniform (SCM state);
97SCM_API SCM scm_random_solid_sphere_x (SCM v, SCM state);
98SCM_API SCM scm_random_hollow_sphere_x (SCM v, SCM state);
99SCM_API SCM scm_random_normal (SCM state);
100SCM_API SCM scm_random_normal_vector_x (SCM v, SCM state);
101SCM_API SCM scm_random_exp (SCM state);
102SCM_API void scm_init_random (void);
e7a72986 103
8c494e99 104#endif /* SCM_RANDOM_H */
89e00824
ML
105
106/*
107 Local Variables:
108 c-file-style: "gnu"
109 End:
110*/