1999-01-10 07:57:27 +00:00
|
|
|
|
/* classes: h_files */
|
|
|
|
|
|
|
2001-08-31 14:42:31 +00:00
|
|
|
|
#ifndef SCM_RANDOM_H
|
|
|
|
|
|
#define SCM_RANDOM_H
|
|
|
|
|
|
|
2010-07-22 18:26:00 +02:00
|
|
|
|
/* Copyright (C) 1999,2000,2001, 2006, 2008, 2010 Free Software Foundation, Inc.
|
2001-08-31 14:42:31 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
2001-08-31 14:42:31 +00:00
|
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-08-31 14:42:31 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
1999-12-16 03:46:42 +00:00
|
|
|
|
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "libguile/__scm.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* A plugin interface for RNGs
|
|
|
|
|
|
*
|
|
|
|
|
|
* Using this interface, it is possible for the application to tell
|
|
|
|
|
|
* libguile to use a different RNG. This is desirable if it is
|
|
|
|
|
|
* necessary to use the same RNG everywhere in the application in
|
|
|
|
|
|
* order to prevent interference, if the application uses RNG
|
|
|
|
|
|
* hardware, or if the application has special demands on the RNG.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Look how the default generator is "plugged in" in scm_init_random().
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
typedef struct scm_t_rstate {
|
2010-07-26 16:36:15 +02:00
|
|
|
|
struct scm_t_rng *rng;
|
2010-07-27 11:32:31 +02:00
|
|
|
|
double normal_next; /* For scm_c_normal01 */
|
1999-01-10 07:57:27 +00:00
|
|
|
|
/* Custom fields follow here */
|
2001-06-14 19:50:43 +00:00
|
|
|
|
} scm_t_rstate;
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
typedef struct scm_t_rng {
|
1999-01-10 07:57:27 +00:00
|
|
|
|
size_t rstate_size; /* size of random state */
|
2010-07-22 21:26:19 +02:00
|
|
|
|
scm_t_uint32 (*random_bits) (scm_t_rstate *state); /* gives 32 random bits */
|
* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,
scm_i_string_writable_chars, scm_i_string_stop_writing): New, to
replace SCM_I_STRING_CHARS and SCM_I_STRING_LENGTH. Updated all
uses.
(scm_i_make_string, scm_c_make_string): New, to replace
scm_allocate_string. Updated all uses.
(SCM_STRINGP, SCM_STRING_CHARS, SCM_STRING_UCHARS,
SCM_STRING_LENGTH): Deprecated.
(scm_allocate_string, scm_take_str, scm_take0str, scm_mem2string,
scm_str2string, scm_makfrom0str, scm_makfrom0str_opt):
Discouraged. Replaced all uses with scm_from_locale_string or
similar, as appropriate.
(scm_c_string_length, scm_c_string_ref, scm_c_string_set_x,
scm_c_substring, scm_c_substring_shared, scm_c_substring_copy,
scm_substring_shared, scm_substring_copy): New.
* symbols.c, symbols.h (SCM_SYMBOLP, SCM_SYMBOL_FUNC,
SCM_SET_SYMBOL_FUNC, SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS,
SCM_SYMBOL_HASH, SCM_SYMBOL_INTERNED_P, scm_mem2symbol,
scm_str2symbol, scm_mem2uninterned_symbol): Discouraged.
(SCM_SYMBOL_LENGTH, SCM_SYMBOL_CHARS, scm_c_symbol2str):
Deprecated.
(SCM_MAKE_SYMBOL_TAG, SCM_SET_SYMBOL_LENGTH, SCM_SET_SYMBOL_CHARS,
SCM_PROP_SLOTS, SCM_SET_PROP_SLOTS): Removed.
(scm_is_symbol, scm_from_locale_symbol, scm_from_locale_symboln):
New, to replace scm_str2symbol and scm_mem2symbol, respectively.
Updated all uses.
(scm_gensym): Generate only the number suffix in the buffer, just
string-append the prefix.
2004-08-19 17:19:44 +00:00
|
|
|
|
void (*init_rstate) (scm_t_rstate *state, const char *seed, int n);
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_rstate *(*copy_rstate) (scm_t_rstate *state);
|
2010-07-26 14:57:46 +02:00
|
|
|
|
void (*from_datum) (scm_t_rstate *state, SCM datum);
|
|
|
|
|
|
SCM (*to_datum) (scm_t_rstate *state);
|
2001-06-14 19:50:43 +00:00
|
|
|
|
} scm_t_rng;
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API scm_t_rng scm_the_rng;
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Random number library functions
|
|
|
|
|
|
*/
|
* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,
scm_i_string_writable_chars, scm_i_string_stop_writing): New, to
replace SCM_I_STRING_CHARS and SCM_I_STRING_LENGTH. Updated all
uses.
(scm_i_make_string, scm_c_make_string): New, to replace
scm_allocate_string. Updated all uses.
(SCM_STRINGP, SCM_STRING_CHARS, SCM_STRING_UCHARS,
SCM_STRING_LENGTH): Deprecated.
(scm_allocate_string, scm_take_str, scm_take0str, scm_mem2string,
scm_str2string, scm_makfrom0str, scm_makfrom0str_opt):
Discouraged. Replaced all uses with scm_from_locale_string or
similar, as appropriate.
(scm_c_string_length, scm_c_string_ref, scm_c_string_set_x,
scm_c_substring, scm_c_substring_shared, scm_c_substring_copy,
scm_substring_shared, scm_substring_copy): New.
* symbols.c, symbols.h (SCM_SYMBOLP, SCM_SYMBOL_FUNC,
SCM_SET_SYMBOL_FUNC, SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS,
SCM_SYMBOL_HASH, SCM_SYMBOL_INTERNED_P, scm_mem2symbol,
scm_str2symbol, scm_mem2uninterned_symbol): Discouraged.
(SCM_SYMBOL_LENGTH, SCM_SYMBOL_CHARS, scm_c_symbol2str):
Deprecated.
(SCM_MAKE_SYMBOL_TAG, SCM_SET_SYMBOL_LENGTH, SCM_SET_SYMBOL_CHARS,
SCM_PROP_SLOTS, SCM_SET_PROP_SLOTS): Removed.
(scm_is_symbol, scm_from_locale_symbol, scm_from_locale_symboln):
New, to replace scm_str2symbol and scm_mem2symbol, respectively.
Updated all uses.
(scm_gensym): Generate only the number suffix in the buffer, just
string-append the prefix.
2004-08-19 17:19:44 +00:00
|
|
|
|
SCM_API scm_t_rstate *scm_c_make_rstate (const char *, int);
|
2010-07-26 14:57:46 +02:00
|
|
|
|
SCM_API scm_t_rstate *scm_c_rstate_from_datum (SCM datum);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API scm_t_rstate *scm_c_default_rstate (void);
|
2010-07-26 16:36:15 +02:00
|
|
|
|
#define scm_c_uniform32(RSTATE) ((RSTATE)->rng->random_bits (RSTATE))
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API double scm_c_uniform01 (scm_t_rstate *);
|
|
|
|
|
|
SCM_API double scm_c_normal01 (scm_t_rstate *);
|
|
|
|
|
|
SCM_API double scm_c_exp1 (scm_t_rstate *);
|
2010-07-22 21:26:19 +02:00
|
|
|
|
SCM_API scm_t_uint32 scm_c_random (scm_t_rstate *, scm_t_uint32 m);
|
2010-08-01 21:53:29 +02:00
|
|
|
|
SCM_API scm_t_uint64 scm_c_random64 (scm_t_rstate *state, scm_t_uint64 m);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_c_random_bignum (scm_t_rstate *, SCM m);
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Scheme level interface
|
|
|
|
|
|
*/
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API scm_t_bits scm_tc16_rstate;
|
2004-05-06 16:43:14 +00:00
|
|
|
|
#define SCM_RSTATEP(obj) SCM_SMOB_PREDICATE (scm_tc16_rstate, obj)
|
|
|
|
|
|
#define SCM_RSTATE(obj) ((scm_t_rstate *) SCM_SMOB_DATA (obj))
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API unsigned char scm_masktab[256];
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API SCM scm_var_random_state;
|
|
|
|
|
|
SCM_API SCM scm_random (SCM n, SCM state);
|
|
|
|
|
|
SCM_API SCM scm_copy_random_state (SCM state);
|
|
|
|
|
|
SCM_API SCM scm_seed_to_random_state (SCM seed);
|
2010-07-26 14:57:46 +02:00
|
|
|
|
SCM_API SCM scm_datum_to_random_state (SCM datum);
|
|
|
|
|
|
SCM_API SCM scm_random_state_to_datum (SCM state);
|
2001-11-02 00:19:12 +00:00
|
|
|
|
SCM_API SCM scm_random_uniform (SCM state);
|
|
|
|
|
|
SCM_API SCM scm_random_solid_sphere_x (SCM v, SCM state);
|
|
|
|
|
|
SCM_API SCM scm_random_hollow_sphere_x (SCM v, SCM state);
|
|
|
|
|
|
SCM_API SCM scm_random_normal (SCM state);
|
|
|
|
|
|
SCM_API SCM scm_random_normal_vector_x (SCM v, SCM state);
|
|
|
|
|
|
SCM_API SCM scm_random_exp (SCM state);
|
2008-05-14 05:20:47 +02:00
|
|
|
|
SCM_INTERNAL void scm_init_random (void);
|
1999-01-10 07:57:27 +00:00
|
|
|
|
|
2001-08-31 14:42:31 +00:00
|
|
|
|
#endif /* SCM_RANDOM_H */
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|