summaryrefslogtreecommitdiff
path: root/libguile/random.c
AgeCommit message (Collapse)AuthorFilesLines
2013-02-25Update copyright dates on random.cMark H Weaver1-1/+2
* libguile/random.c: Add 2012 and 2013 to the copyright notice.
2013-02-25random_state_of_last_resort: use getpid directly, instead of scm_getpidMark H Weaver1-2/+9
* libguile/random.c: Include <sys/types.h> and <unistd.h> (if present). (random_state_of_last_resort): Use getpid directly.
2013-02-25Revert "random_state_of_last_resort doesn't rely on HAVE_POSIX"Mark H Weaver1-6/+3
This reverts commit eaf21539d4afb8df5d1b549215fd397b23004947.
2013-02-25Revert "random-state-from-platform: simplify pid conditional, and clarify docs."Mark H Weaver1-8/+9
This reverts commit 08904661a2b1c6d461b2f5abfe3226a4023453fb.
2013-02-24random-state-from-platform: simplify pid conditional, and clarify docs.Mark H Weaver1-9/+8
* libguile/random.c (random_state_of_last_resort): Simplify optional inclusion of PID in the random state. Clarify in the comments that the PID is only included where scm_getpid is present. * doc/ref/api-data.texi (Random): Clarify that 'random-state-from-platform' includes the PID in the random state only if scm_getpid is present.
2013-02-24random_state_of_last_resort doesn't rely on HAVE_POSIXAndy Wingo1-3/+6
* libguile/random.c (random_state_of_last_resort): Add the PID as a seed only if we have scm_getpid().
2012-01-21Add `random-state-from-platform' and `scm_i_random_bytes_from_platform'Mark H Weaver1-0/+101
* libguile/random.c (scm_random_state_from_platform): New procedure. (scm_i_random_bytes_from_platform): New internal function. * libguile/random.h (scm_random_state_from_platform, scm_i_random_bytes_from_platform): Add prototypes. * doc/ref/api-data.texi (Random): Add documentation.
2011-02-09fix typos in the manual bits generated from source comments.Ralf Wildenhues1-1/+1
* libguile/bitvectors.c, libguile/chars.c, libguile/deprecated.c, libguile/numbers.c, libguile/random.c, libguile/read.c, libguile/root.c, libguile/srfi-1.c, libguile/srfi-13.c, libguile/srfi-14.c, libguile/uniform.c: Fix typos, add missing newlines.
2010-11-19fix a number of assuptions that a long could hold an inumAndy Wingo1-4/+4
* libguile/bytevectors.c: * libguile/goops.c: * libguile/instructions.c: * libguile/numbers.c: * libguile/random.c: * libguile/read.c: * libguile/vm-i-scheme.c: Fix a number of assumptions that a long could hold an inum. This is not the case on platforms whose void* is larger than their long. * libguile/numbers.c (scm_i_inum2big): New helper, only implemented for sizeof(void*) == sizeof(long); produces a compile error on other platforms. Basically gmp doesn't have a nice interface for converting between mpz values and intmax_t.
2010-08-01Fix the range of `random' on 64-bit platformsAndreas Rottmann1-15/+27
For > 32 bit integers still in the fixnum range, scm_random() would return random numbers with a lower range than specified. * libguile/random.c (scm_i_mask32): New static inline function. (scm_c_random): Use `scm_i_mask32'. (scm_c_random64): New function, 64-bit variant of scm_c_random. (scm_random): Use `scm_c_random64' instead of forming the 64-bit random number in a bogus way. * libguile/random.h: Added `scm_c_random64'.
2010-07-2764-bit random fixesAndy Wingo1-3/+20
* libguile/random.c (scm_random): Fix generation of inum randoms with more than 32 bits. * libguile/random.h (scm_t_rstate): Fix a comment.
2010-07-26rstates point to rngsAndy Wingo1-19/+23
* libguile/random.h (scm_t_rstate): Include the rng in the rstate, so we can actually have multiple rngs. Instead of reserved0 / reserved1, reserve a double explicitly for scm_c_normal01. (scm_c_uniform32): Change to call the rstate's rng. * libguile/random.c: Change to access an rstate's rng through its rng pointer. (scm_c_normal01): Instead of a flag and a next double, just check that the double is equal to 0.0. Excluding one value shouldn't affect the distribution, right?
2010-07-26update docsAndy Wingo1-4/+2
* doc/ref/api-data.texi: * libguile/random.c: Update datum->random-state and random-state->datum docs.
2010-07-26refactor datum->random-state / random-state->datumAndy Wingo1-38/+50
* libguile/random.c (scm_t_i_rstate): Move here from random.h, along with prototypes for functions (scm_i_uniform32, scm_i_init_rstate, scm_i_copy_rstate): Change to take a stock scm_t_rstate as an arg, and cast it. This way we don't cast the pointers below. (scm_i_rstate_from_datum, scm_i_rstate_from_datum): Same and rename from scm_i_init_rstate_scm / scm_i_expose_rstate. (scm_c_rstate_from_datum): Rename from scm_c_make_rstate_scm. (scm_datum_to_random_state, scm_random_state_to_datum): Rename from scm_external_to_random_state and scm_random_state_to_external. (scm_init_random): Remove casts. * libguile/random.h (scm_t_rng): Rename init_rstate_scm, expose_rstate vmethods to from_datum, to_datum. Remove internal definitions. Rename to scm_c_rstate_from_datum, and provide scm_random_state_to_datum and scm_datum_to_random_state.
2010-07-26low-level RNG interfaces deal in scm_t_uint32, not unsigned longAndy Wingo1-54/+28
* libguile/random.h (scm_t_rng): random_bits returns a scm_t_uint32. (scm_i_uniform32, scm_t_i_rstate): Internal RNG returns a scm_t_uint32, as advertised, instead of unsigned long. (scm_c_random): Return a scm_t_uint32 instead of an unsigned long. * libguile/random.c (scm_i_uniform32, scm_i_init_rstate_scm): (scm_i_expose_rstate, scm_c_random, scm_c_random_bignum, scm_random) (scm_init_random): Adapt types to match implementation.
2010-07-26remove SCM_HAVE_T_INT64, SCM_HAVE_T_UINT64Andy Wingo1-34/+0
* libguile/__scm.h: * libguile/numbers.h: * libguile/random.c: * libguile/srfi-4.c: * libguile/srfi-4.h: * libguile/numbers.c: * test-suite/standalone/test-conversion.c: * libguile/gen-scmconfig.c: As we require 64-bit integers in configure.ac, remove conditional definition of 64-bit types.
2010-07-26Allow exposing of random number generator stateAndreas Rottmann1-4/+68
Now the random number generator state can be obtained in external (i.e. `read'/`write'-able) form via the new procedure `random-state->external'. An externalized state can be reinstantiated by calling `external->random-state'. * libguile/random.c (scm_i_init_rstate_scm, scm_i_expose_rstate): New internal functions. * libguile/random.c (scm_c_make_rstate_scm, scm_external_to_random_state, scm_random_state_to_external): New public functions. * libguile/random.h: Add prototypes for the above functions. * libguile/random.h (scm_t_rng): Add new fields `init_rstate_scm' and `expose_rstate'. * libguile/random.c (scm_init_random): Initialize the new fields in `scm_the_rng'.
2010-07-19Fix random number generator on 64-bit platformsAndreas Rottmann1-1/+27
* libguile/random.c (scm_c_random): On platforms where `unsigned long' has 64 bit, generate up to 64 bit of randomness. This is expected by scm_c_random_bignum(), and hence was a serious distortion of the random value distribution for values exceeding 2^32. This change also fixes a crash when the `m' argument is a value above 2^32.
2009-08-28Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-2/+3
Conflicts: libguile/Makefile.am libguile/bytevectors.c libguile/gc-card.c libguile/gc-mark.c libguile/programs.c libguile/srcprop.c libguile/srfi-14.c libguile/symbols.c libguile/threads.c libguile/unif.c libguile/vm.c
2009-08-18Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-6/+7
Conflicts: lib/Makefile.am libguile/Makefile.am libguile/frames.c libguile/gc-card.c libguile/gc-freelist.c libguile/gc-mark.c libguile/gc-segment.c libguile/gc_os_dep.c libguile/load.c libguile/macros.c libguile/objcodes.c libguile/programs.c libguile/strings.c libguile/vm.c m4/gnulib-cache.m4 m4/gnulib-comp.m4 m4/inline.m4
2009-07-19generic vector ops to own fileAndy Wingo1-0/+1
* libguile/Makefile.am: * libguile/vectors.c: * libguile/vectors.h: * libguile/generalized-vectors.c: * libguile/generalized-vectors.h: Move generic vector ops off into their own file too. The implementation is now based on the generic array-handle infrastructure. * libguile.h: * libguile/array-map.c: * libguile/bitvectors.c: * libguile/random.c: * libguile/srfi-4.c: Update includers.
2009-07-19rename unif.[ch] to arrays.[ch]Andy Wingo1-2/+2
* libguile/Makefile.am: * libguile/unif.c: * libguile/unif.h: * libguile/arrays.c: * libguile/arrays.h: Rename unif.[ch] to arrays.[ch]. * libguile.h: * libguile/array-handle.c: * libguile/array-map.c: * libguile/bitvectors.c: * libguile/bytevectors.c: * libguile/eq.c: * libguile/gc-card.c: * libguile/gc-malloc.c: * libguile/gc-mark.c: * libguile/gc.c: * libguile/init.c: * libguile/inline.h: * libguile/print.c: * libguile/random.c: * libguile/read.c: * libguile/socket.c: * libguile/sort.c: * libguile/srfi-4.c: * libguile/srfi-4.h: * libguile/strports.c: * libguile/vectors.c: * libguile/vectors.h: Update includers.
2009-06-17Change Guile license to LGPLv3+Neil Jerram1-6/+7
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2008-09-13Merge branch 'master' into boehm-demers-weiser-gcLudovic Courtès1-1/+1
Conflicts: lib/Makefile.am libguile/gc-card.c libguile/gc-freelist.c libguile/gc-mark.c libguile/gc-segment.c libguile/gc.c libguile/gc.h libguile/gc_os_dep.c libguile/private-gc.h m4/.cvsignore m4/gnulib-cache.m4 m4/gnulib-comp.m4
2008-09-13Include <config.h> in all C files; use `#ifdef HAVE_CONFIG_H' rather than `#if'.Ludovic Courtès1-1/+1
2008-09-10Use `scm_gc_malloc_pointerless' in various places (improves performance).Ludovic Courtes1-4/+8
* libguile/fports.c (scm_fport_buffer_add): Use `scm_gc_malloc_pointerless ()' instead of `scm_gc_malloc ()' when allocating room for the read/write buffers. * libguile/numbers.c (scm_c_make_rectangular): Likewise. * libguile/ports.c (scm_ungetc): Likewise. * libguile/random.c (scm_i_copy_rstate): Likewise. (scm_c_make_rstate): Likewise. * libguile/regex-posix.c (scm_make_regexp): Likewise. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-36
2008-09-05Removed a lot of now-useless SMOB mark/free functions.Ludovic Courtes1-9/+4
* libguile/arbiters.c (scm_init_arbiters): Don't invoke `scm_set_smob_mark'. * libguile/async.c (async_gc_mark): Removed. (scm_init_async): Don't invoke `scm_set_smob_mark'. * libguile/coop-pthreads.c (thread_mark): Removed. (create_thread): Use `scm_gc_malloc' instead of `scm_malloc' when allocating `launch_data'. (mutex_mark): Removed. (scm_threads_init): Don't invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/debug.c (scm_init_debug): Don't invoke `scm_set_smob_mark'. * libguile/dynl.c (dynl_obj_mark): Removed. (scm_init_dynamic_linking): Don't invoke `scm_set_smob_mark'. * libguile/dynwind.c (winder_mark): Removed. (scm_init_dynwind): Don't invoke `scm_set_smob_mark'. * libguile/environments.c (environment_mark): Removed. (environment_free): Removed. (observer_mark): Removed. (core_environments_mark): Removed. (core_environments_finalize): Removed. (leaf_environment_mark): Removed. (leaf_environment_free): Removed. (leaf_environment_funcs): Don't refer to the above funcs. (eval_environment_mark): Removed. (eval_environment_free): Removed. (eval_environment_funcs): Don't refer to the above funcs. (import_environment_mark): Removed. (import_environment_free): Removed. (import_environment_funcs): Don't refer to the above funcs. (export_environment_mark): Removed. (export_environment_free): Removed. (export_environment_funcs): Don't refer to the above funcs. (scm_environments_prehistory): Don't invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/environments.h (scm_environment_funcs)[mark]: Removed. [free]: Removed. * libguile/eval.c (promise_mark): Removed. (promise_free): Removed. (scm_init_eval): Don't invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/fluids.c (fluid_free): Removed. (scm_fluids_prehistory): Don't invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/futures.c (future_mark): Removed. (scm_init_futures): Don't invoke `scm_set_smob_mark'. * libguile/hashtab.c (hashtable_free): Removed. (scm_hashtab_prehistory): Don't invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/hooks.c (scm_init_hooks): Don't invoke `scm_set_smob_mark'. * libguile/keywords.c (scm_init_keywords): Don't invoke `scm_set_smob_mark'. * libguile/macros.c (scm_init_macros): Don't invoke `scm_set_smob_mark'. * libguile/modules.c (scm_init_modules): Don't invoke `scm_set_smob_mark'. * libguile/print.c (scm_init_print): Don't invoke `scm_set_smob_mark'. * libguile/random.c (scm_i_copy_rstate): Use `scm_gc_malloc' instead of `scm_malloc'. (scm_c_make_rstate): Likewise. (rstate_free): Removed. (scm_init_random): Don't invoke `scm_set_smob_free'. * libguile/srcprop.c (srcprops_mark): Removed. (scm_init_srcprop): Don't invoke `srcprops_mark'. * libguile/srfi-14.c (charset_free): Removed. (scm_init_srfi_14): Don't invoke `scm_set_smob_free'. * libguile/srfi-4.c (uvec_mark): Removed. (uvec_free): Removed. (scm_init_srfi_4): Don't invoke `scm_set_smob_free' and `scm_set_smob_mark'. * libguile/threads.c (thread_mark): Removed. (fat_mutex_mark): Removed. (fat_cond_mark): Removed. (scm_init_threads): Dont invoke `scm_set_smob_mark' and `scm_set_smob_free'. * libguile/unif.c (bitvector_free): Removed. (array_mark): Removed. (array_free): Removed. (scm_init_unif): Don't invoke `scm_set_smob_free' and `scm_set_smob_mark'. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-28
2006-04-17merge from 1.8 branchKevin Ryde1-1/+1
2006-02-19Test for SCM_HAVE_T_UINT64 instead ofMikael Djurfeldt1-11/+11
SCM_HAVE_T_INT64. (scm_i_uniform32, scm_i_uniform32, scm_i_init_rstate): Use scm_t_uint64 and scm_t_uint32 instead of scm_t_int64 and scm_t_int32.
2005-11-26(scm_i_copy_rstate, scm_c_make_rstate): Don't test forKevin Ryde1-5/+1
scm_malloc returning NULL, it never does that.
2005-05-23The FSF has a new address.Marius Vollmer1-1/+1
2005-01-23(scm_i_init_rstate): Compare w to -1 not 0xffffffffUL, nowKevin Ryde1-1/+1
that it's an scm_t_int32. Otherwise gcc 3.4 says it's always false on a 64-bit system.
2005-01-17(scm_random_solid_sphere_x): Use scm_c_generalized_vector_lengthMarius Vollmer1-1/+1
instead of scm_uniform_vector_length.
2005-01-15(scm_random_solid_sphere_x): Update docstring from manual.Kevin Ryde1-6/+5
2005-01-14Don't check for definedness of SCM_HAVE_T_INT64, checkMarius Vollmer1-1/+1
its value.
2005-01-06(scm_array_handle_release): New, changed all uses ofMarius Vollmer1-1/+6
scm_t_array_handle to properly call it. (scm_vector_get_handle, scm_generalized_vector_get_handle): Renamed former to latter, changed all uses.
2005-01-02Use new vector elements API or simple vector API, as appropriate.Marius Vollmer1-31/+40
Removed SCM_HAVE_ARRAYS ifdefery. Replaced all uses of SCM_HASHTABLE_BUCKETS with SCM_HASHTABLE_BUCKET.
2004-12-27(scm_uniform_vector_elements,Marius Vollmer1-6/+6
scm_u8vector_elements, etc): Made return value "const". (scm_uniform_vector_writable_elements, scm_u8vector_writable_elements, etc): New. (scm_uniform_vector_release, scm_uniform_vector_release_elements): Renamed former to latter. Added explicit call to scm_remember_upto_here_1. (scm_frame_uniform_vector_release, scm_frame_uniform_vector_release_elements): Renamed former to latter. (scm_uniform_vector_release_writable_elements, scm_frame_uniform_vector_release_writable_elements): New. Takes crown of longest identifier yet. Changed all uses as required by the changes above.
2004-11-02(scm_random_solid_sphere_x, scm_random_hollow_sphere_x): Do notMarius Vollmer1-2/+0
validate vector argument, this is already done elsewhere.
2004-10-27(vector_scale, vector_scale_x): Renamed former to theMarius Vollmer1-29/+57
latter, since it modifies its argument. (vector_scale_x, vector_sum_squares, scm_random_normal_vector_x): Do not use scm_universal_vector_length for non-uniform vectors. Use scm_f64vector_elements to access innards of uniform vectors.
2004-08-19* strings.h, strings.c: (scm_i_string_chars, scm_i_string_length,Marius Vollmer1-5/+5
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-12* socket.c, rw.c, deprecated.h, validate.hMarius Vollmer1-2/+6
(SCM_VALIDATE_STRING_COPY): Deprecated. Replaced all uses with SCM_VALIDATE_STRING plus SCM_I_STRING_CHARS or scm_to_locale_string, etc. (SCM_VALIDATE_SUBSTRING_SPEC_COPY): Deprecated. Replaced as above, plus scm_i_get_substring_spec. * regex-posix.c, read.c, random.c, ramap.c, print.c, numbers.c, hash.c, gc.c, gc-card.c, convert.i.c, backtrace.c, strop.c, strorder.c, strports.c, struct.c, symbols.c, unif.c, ports.c: Use SCM_I_STRING_CHARS, SCM_I_STRING_UCHARS, and SCM_I_STRING_LENGTH instead of SCM_STRING_CHARS, SCM_STRING_UCHARS, and SCM_STRING_LENGTH, respectively. Also, replaced scm_return_first with more explicit scm_remember_upto_here_1, etc, or introduced them in the first place.
2004-08-03(scm_make_real, scm_num2dbl, scm_float2num, scm_double2num):Marius Vollmer1-6/+6
Discouraged by moving to discouraged.h and discouraged.c. Replaced all uses with scm_from_double. (scm_num2float, scm_num2double): Discouraged by moving prototype to discouraged.h and rewriting in terms of scm_to_double. Replaced all uses with scm_to_double.
2004-07-23* deprecated.h, deprecated.c, numbers.h (SCM_INUMP, SCM_NINUMP,Marius Vollmer1-7/+7
SCM_INUM): Deprecated by reenaming them to SCM_I_INUMP, SCM_I_NINUMP and SCM_I_INUM, respectively and adding deprecated versions to deprecated.h and deprecated.c. Changed all uses to either use the SCM_I_ variants or scm_is_*, scm_to_*, or scm_from_*, as appropriate.
2004-07-10* validate.h, deprecated.h (SCM_VALIDATE_INUM, SCM_VALIDATE_INUM_COPY,Marius Vollmer1-1/+2
SCM_VALIDATE_BIGINT, SCM_VALIDATE_INUM_MIN, SCM_VALIDATE_INUM_MIN_COPY, SCM_VALIDATE_INUM_MIN_DEF_COPY,SCM_VALIDATE_INUM_DEF, SCM_VALIDATE_INUM_DEF_COPY, SCM_VALIDATE_INUM_RANGE, SCM_VALIDATE_INUM_RANGE_COPY): Deprecated because they make the fixnum/bignum distinction visible. Changed all uses to scm_to_size_t or similar.
2004-07-08* numbers.h (SCM_MAKINUM, SCM_I_MAKINUM): Renamed SCM_MAKINUM toMarius Vollmer1-1/+1
SCM_I_MAKINUM and changed all uses.
2003-04-16* random.c (scm_c_random_bignum): use SCM_CHAR_BIT.Rob Browning1-3/+4
2003-04-07* random.c: #include gmp.h.Rob Browning1-4/+2
(scm_c_random_bignum): normalize result on return.
2003-04-06* random.c (scm_c_default_rstate): Use SCM_VARIABLE_REF to accessMikael Djurfeldt1-1/+1
scm_var_random_state.
2003-04-06* random.c (scm_c_random_bignum): Don't generate a random numberMikael Djurfeldt1-7/+4
equal to m (the second argument of scm_c_random_bignum); only generate numbers in the range 0 <= r < m.