[[tags: egg]] == SRFI 27 Source of Random Bits (Implementation) [[toc:]] == Documentation The implementation API for the Chicken [[http://srfi.schemers.org/srfi-27/srfi-27.html|SRFI 27]]. === SRFI 27 These routines are '''unsafe''' and not meant for general consumption. ('''Note''' that some procedures are re-exported by the {{srfi-27}} module. If you get this far you can probably deal with it.) === Random Source Object ==== Usage (use random-source) ==== *make-random-source (*make-random-source @CTOR *NAME *DOCU *LOG2-PERIOD *MAXRNG *ES @STATE-REF @STATE-SET! @RANDOMIZE! @PSEUDO-RANDOMIZE! @MAKE-INTEGERS @MAKE-REALS) => random-source ==== random-source? (random-source? OBJ) => boolean (check-random-source LOC OBJ [NAM]) (error-random-source LOC OBJ [NAM]) ==== *random-source-name (*random-source-name RANDOM-SOURCE) ==== *random-source-documentation (*random-source-documentation RANDOM-SOURCE) ==== *random-source-log2-period (*random-source-log2-period RANDOM-SOURCE) ==== *random-source-maximum-range (*random-source-maximum-range RANDOM-SOURCE) ==== *random-source-entropy-source (*random-source-entropy-source RANDOM-SOURCE) ==== *random-source-entropy-source-set! (*random-source-entropy-source-set! RANDOM-SOURCE ENTROPY-SOURCE) ==== @random-source-construtor (@random-source-construtor RANDOM-SOURCE) ==== @random-source-state-ref (@random-source-state-ref RANDOM-SOURCE) ==== @random-source-state-set! (@random-source-state-set! RANDOM-SOURCE SDTATE) ==== @random-source-randomize! (@random-source-randomize! RANDOM-SOURCE) ==== @random-source-pseudo-randomize! (@random-source-pseudo-randomize! RANDOM-SOURCE) ==== @random-source-make-integers (@random-source-make-integers RANDOM-SOURCE) ==== @random-source-make-reals (@random-source-make-reals RANDOM-SOURCE) ==== register-random-source (register-random-source NAME MAKER) {{NAME}} is a {{symbol}} uniquely identifing a {{random-source}} generator. {{MAKER}} is a {{(procedure () random-source)}}. ==== registered-random-sources (registered-random-sources) => (list-of symbol) ==== registered-random-source (registered-random-source NAME) => (disjoint #f (procedure () random-source)) ==== unregister-random-source (unregister-random-source NAME) === Entropy Source Object ==== Usage (use entropy-source) ==== *make-entropy-source (*make-entropy-source @CTOR *NAME *DOCU @U8 @F64 @U8VEC @F64VEC) => entropy-source ==== entropy-source? (entropy-source? OBJ) => boolean (check-entropy-source LOC OBJ [NAM]) (error-entropy-source LOC OBJ [NAM]) ==== *entropy-source-name (*entropy-source-name ENTROPY-SOURCE) ==== *entropy-source-documentation (*entropy-source-documentation ENTROPY-SOURCE) ==== @entropy-source-construtor (@entropy-source-construtor ENTROPY-SOURCE) ==== @entropy-source-u8 (@entropy-source-u8 ENTROPY-SOURCE) ==== @entropy-source-f64 (@entropy-source-f64 ENTROPY-SOURCE) ==== @entropy-source-u8vector (@entropy-source-u8vector ENTROPY-SOURCE) ==== @entropy-source-f64vector (@entropy-source-f64vector ENTROPY-SOURCE) ==== register-entropy-source (register-entropy-source NAME MAKER) {{NAME}} is a {{symbol}} uniquely identifing an {{entropy-source}} generator. {{MAKER}} is a {{(procedure () entropy-source)}}. ==== registered-entropy-sources (registered-entropy-sources) => (list-of symbol) ==== registered-entropy-source (registered-entropy-source NAME) => (disjoint #f (procedure () entropy-source)) ==== unregister-entropy-source (unregister-entropy-source NAME) === Entropy Support ==== Usage (use entropy-support) ==== port-entropic-f64vector (port-entropic-f64vector PORT F64CNT F64VEC #!optional (F64GET port-entropic-f64)) Fills the first {{F64CNT}} elements of {{F64VEC}} with f64 values pulled from the {{PORT}}, using the {{F64GET}} {{procedure}}. ==== port-entropic-u8vector (port-entropic-u8vector PORT U8CNT U8VEC) Fills the first {{U8CNT}} elements of {{U8VEC}} with u8 values pulled from the {{PORT}}. ==== port-entropic-f64 (port-entropic-f64 PORT) => flonum Returns an f64 value pulled from the {{PORT}}. ==== port-entropic-u8 (port-entropic-u8 PORT) => fixnum Returns a u8 value pulled from the {{PORT}}. ==== entropic-f64vector-filled (entropic-f64vector-filled F64CNT F64VEC F64GEN) Fills the first {{F64CNT}} elements of {{F64VEC}} with u8 values from the supplied f64 generator {{F64GEN}}. ==== entropic-u8vector-filled (entropic-u8vector-filled U8CNT U8VEC U8GEN) Fills the first {{U8CNT}} elements of {{U8VEC}} with u8 values from the supplied u8 generator {{U8GEN}}. ==== entropic-f64vector-filled/u8 (entropic-f64vector-filled/u8 F64CNT F64VEC U8GEN) Fills the first {{F64CNT}} elements of {{F64VEC}} with u8 values from the supplied u8 generator {{U8GEN}}. ==== entropic-u8vector-filled/f64 (entropic-u8vector-filled/f64 U8CNT U8VEC F64GEN) Fills the first {{U8CNT}} elements of {{U8VEC}} with u8 values from the supplied f64 generator {{F64GEN}}. ==== make-entropic-f64/u8 (make-entropic-f64/u8 U8GEN) => procedure Returns an f64 generator built from the supplied u8 generator {{U8GEN}}. ==== make-entropic-u8/f64 (make-entropic-u8/f64 F64GEN) => procedure Returns a u8 generator built from the supplied f64 generator {{F64GEN}}. == Examples == Notes * Due to the SRFI 27 requirement to generate numbers of any precision the "numbers" extension is always loaded. Be careful of creating a generator in a calling context where extended range is possible and consuming the results of the generator in a context without such range. * Portions by Sebastian Egner and Brad Lucier. (See the "book" SRFI 27 implementation.) == Bugs and Limitations * {{composite-random-source}} is questionable. * The distributions are poorly documented. == Author [[kon lovett]] == Version history ; 3.1.0 : Changed {{random-source-name}}s to lowercase symbols. Changed {{random-state}} tags to same as {{random-source-name}}. Added {{new-(random|entroppy)-source}}, {{@(random|entroppy)-source-constructor}} & {{(random|entroppy)-source-name}}. Exported {{registered-(random|entroppy)-sources}} & {{registered-(random|entroppy)-source}}. ; 3.0.1 : Bug fix for bad external state symbol. Use of 64-bit arithmetic instead of double. ; 3.0.0 : Initial release for Chicken 4 == License Copyright (C) 2010 Kon Lovett. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Does not supercede any restrictions found in the source code.