Changeset 5656 in project


Ignore:
Timestamp:
08/23/07 18:37:42 (12 years ago)
Author:
Kon Lovett
Message:

Added automatic "open" of entropy & random sources, per SRFI-27 document. Added automatic open when corresponding parameter set. Renamed entropy to entropy-parameters.

Location:
srfi-27
Files:
1 added
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • srfi-27/entropy-common.scm

    r5147 r5656  
    66     COMMON-ENTROPY-SOURCE-STRUCTURE
    77     (lexmod ,(gensym "@entropy-source-")
    8        (export make-entropy-source entropy-kind
     8       (export make-entropy-source entropy-source entropy-kind
    99               entropic-u8 entropic-f64
    1010               entropic-u8vector entropic-f64vector)
    1111       (define (make-entropy-source) (,MAKE-PROC) )
    1212       (define entropy-source (,MAKE-PROC) )
    13        (define (entropy-kind) ((%entropy-kind entropy-source)) )
     13       (define (entropy-kind) (%entropy-kind entropy-source) )
    1414       (define (entropic-u8) ((%entropy-source-u8 entropy-source)) )
    1515       (define (entropic-f64) ((%entropy-source-f64 entropy-source)) )
  • srfi-27/entropy-primitives.scm

    r5147 r5656  
    173173(define-parameter current-entropy-port-close-seconds DEFAULT-ENTROPY-PORT-CLOSE-SECONDS
    174174  (lambda (x)
    175     (if (and (or (fixnum? x) (flonum? x)) (positive? x))
    176       x
    177       (current-entropy-port-close-seconds) ) ) )
     175    (cond [(and (or (fixnum? x) (flonum? x)) (positive? x))
     176            x]
     177          [else
     178            (warning "invalid seconds value" x)
     179            (current-entropy-port-close-seconds)] ) ) )
    178180
    179181;; Timeout Job
  • srfi-27/moa-primitives.scm

    r5147 r5656  
    268268(define (make-moa-random-source)
    269269  (let ([state *moa-initial-state*])
    270     (%make-random-source 'MOA
    271       LOG2-PERIOD MAXIMUM-RANGE M1
     270    (%make-random-source 'MOA LOG2-PERIOD MAXIMUM-RANGE M1
    272271      (lambda ()
    273272        (moa-state-ref state))
  • srfi-27/srfi-27-distributions.scm

    r5231 r5656  
    3737;;;
    3838
    39 ; (could include mathh-constants here)
    40 
    41 (define-constant PI 3.1415926535897932384626433832795028841972)
    42 (define-constant E  2.7182818284590452353602874713526624977572)
     39(define-constant PI                                     3.1415926535897932384626433832795028841972)   ; pi
    4340
    4441(define-constant |1/3| 0.3333333333333333333333333333333333333333)
  • srfi-27/srfi-27-eggdoc.scm

    r5147 r5656  
    3838    (author (url "mailto:klovett@pacbell.net" "Kon Lovett"))
    3939    (history
     40      (version "2.1" "Automatic open of MRG32k3a, current-seconds-entropy, and when corresponding parameter changed.")
    4041      (version "2.000" "Use of lexmod. Incompatible.")
    4142      (version "1.511" "Dropped :optional")
     
    7475      (url "http://srfi.schemers.org/srfi-27/srfi-27.html" "SRFI-27") ".")
    7576
    76       (p "A random-structure is not \"open\" by default. To use the SRFI-27 "
    77       "random structure do the following: "
    78       (code "(require-extension lexmod srfi-27) (lexmod-open MRG32k3a)") ". "
    79       "This is a violation of the SRFI-27 specification.")
    80 
    81       (p "The distributions are not automatically loaded. The extension needs an "
    82       "explicit " (code "(require-extension srfi-27-distributions)") ". This is a "
     77      (p "The distributions are not automatically loaded. An explicit "
     78      (code "(require-extension srfi-27-distributions)") ". A "
    8379      "violation of the SRFI-27 specification.")
    8480
     
    9389              "(-> %entropy-source)")
    9490            (describe entropy-source?
    95               "(-> any boolean)")
     91              "(-> object boolean)")
     92            (describe entropy-source
     93              "(-> %entropy-source)")
    9694            (describe entropy-kind
    9795              "(-> (or string symbol))")
     
    119117              "(-> %random-source)")
    120118            (describe random-source?
    121               "(-> any boolean)")
     119              "(-> object boolean)")
    122120            (describe random-source-kind
    123121              "(-> %random-source (or string symbol))")
     
    147145        "entropy source. See " (code "current-entropy-source-structure") " below.")
    148146
     147        (p "To use a random structure do the following: "
     148        (code "(require-extension lexmod srfi-27) (lexmod-open RANDOM-SOURCE-STRUCTURE)") ", "
     149        "where RANDOM-SOURCE-STRUCTURE is one of the structures below.")
     150
    149151        (definition
    150152          (signatures
     
    273275
    274276        (parameter "(current-entropy-source-structure [ENTROPY-SOURCE-STRUCTURE current-seconds-entropy])"
    275           (p "Returns or sets the current entropy source structure."))
     277          (p "Returns or sets the current entropy source structure.")
     278
     279          (p "The " (tt "ENTROPY-SOURCE-STRUCTURE") " is automatically \"opened\"!") )
    276280
    277281        (parameter "(current-random-source-structure [RANDOM-SOURCE-STRUCTURE MRG32k3a])"
    278           (p "Returns or sets the current random source structure."))
     282          (p "Returns or sets the current random source structure.")
     283
     284          (p "The " (tt "RANDOM-SOURCE-STRUCTURE") " is automatically \"opened\"!") )
    279285
    280286        (parameter "(current-entropy-port-close-seconds [SECONDS 10.0])"
  • srfi-27/srfi-27-parameters.scm

    r2973 r5656  
    22;;;; Kon Lovett, May '06
    33
     4(use syntax-case lexmod)
    45(use miscmacros srfi-27-structures mrg32k3a)
    56
     
    1314
    1415;;
     16
    1517(define-parameter current-random-source-structure MRG32k3a
    1618  (lambda (x)
    17     (cond
    18       [(random-source-structure? x)
    19         x]
    20       [else
    21         (current-random-source-structure)])) )
     19    (let ([struct
     20            (cond [(random-source-structure? x) x]
     21                  [else
     22                    (warning "invalid random-source-structure" x)
     23                    (current-random-source-structure)])])
     24      (lexmod-open struct)
     25      struct ) ) )
  • srfi-27/srfi-27-structures.scm

    r5147 r5656  
    1010;; is a 'module'!
    1111
    12 (use srfi-1 srfi-9 syntax-case lexmod)
     12(use srfi-1 srfi-9)
     13(use syntax-case lexmod)
    1314
    1415(eval-when (compile)
  • srfi-27/srfi-27.html

    r5147 r5656  
    158158<h3>Version</h3>
    159159<ul>
     160<li>2.1 Automatic open of MRG32k3a, current-seconds-entropy, and when corresponding parameter changed.</li>
    160161<li>2.000 Use of lexmod. Incompatible.</li>
    161162<li>1.511 Dropped :optional</li>
     
    181182<li><a href="lexmod.html">lexmod</a></li>
    182183<li><a href="miscmacros.html">miscmacros</a></li>
    183 <li><a href="misc-extn.html">misc-extn</a></li>
    184184<li><a href="numbers.html">numbers</a></li>
    185185<li><a href="vector-lib.html">vector-lib</a></li>
     
    193193<h3>Documentation</h3>
    194194<p>This is a Chicken implementation of SRFI-27. This document only describes the extensions and violations. For the SRFI-27 API see <a href="http://srfi.schemers.org/srfi-27/srfi-27.html">SRFI-27</a>.</p>
    195 <p>A random-structure is not &quot;open&quot; by default. To use the SRFI-27 random structure do the following: <code>(require-extension structures srfi-27) (lexmod-open MRG32k3a)</code>. This is a violation of the SRFI-27 specification.</p>
    196 <p>The distributions are not automatically loaded. The extension needs an explicit <code>(require-extension srfi-27-distributions)</code>. This is a violation of the SRFI-27 specification.</p>
     195<p>The distributions are not automatically loaded. An explicit <code>(require-extension srfi-27-distributions)</code>. A violation of the SRFI-27 specification.</p>
    197196<div class="subsection">
    198197<h4>Signatures</h4>
     
    204203<tr>
    205204<td class="symbol">entropy-source?</td>
    206 <td>(-&gt; any boolean)</td></tr>
     205<td>(-&gt; object boolean)</td></tr>
     206<tr>
     207<td class="symbol">entropy-source</td>
     208<td>(-&gt; %entropy-source)</td></tr>
    207209<tr>
    208210<td class="symbol">entropy-kind</td>
     
    236238<tr>
    237239<td class="symbol">random-source?</td>
    238 <td>(-&gt; any boolean)</td></tr>
     240<td>(-&gt; object boolean)</td></tr>
    239241<tr>
    240242<td class="symbol">random-source-kind</td>
     
    270272<h4>Random Source Structures</h4>
    271273<p>All random number generators are randomized using the current entropy source. See <code>current-entropy-source-structure</code> below.</p>
     274<p>To use a random structure do the following: <code>(require-extension lexmod srfi-27) (lexmod-open RANDOM-SOURCE-STRUCTURE)</code>, where RANDOM-SOURCE-STRUCTURE is one of the structures below.</p>
    272275<dt class="definition"><strong>lexmod:</strong> (MRG32k3a (random-source-signature))</dt>
    273276<dd>
     
    354357<dt class="definition"><strong>parameter:</strong> (current-entropy-source-structure [ENTROPY-SOURCE-STRUCTURE current-seconds-entropy])</dt>
    355358<dd>
    356 <p>Returns or sets the current entropy source structure.</p></dd>
     359<p>Returns or sets the current entropy source structure.</p>
     360<p>The <tt>ENTROPY-SOURCE-STRUCTURE</tt> is automatically &quot;opened&quot;!</p></dd>
    357361<dt class="definition"><strong>parameter:</strong> (current-random-source-structure [RANDOM-SOURCE-STRUCTURE MRG32k3a])</dt>
    358362<dd>
    359 <p>Returns or sets the current random source structure.</p></dd>
     363<p>Returns or sets the current random source structure.</p>
     364<p>The <tt>RANDOM-SOURCE-STRUCTURE</tt> is automatically &quot;opened&quot;!</p></dd>
    360365<dt class="definition"><strong>parameter:</strong> (current-entropy-port-close-seconds [SECONDS 10.0])</dt>
    361366<dd>
  • srfi-27/srfi-27.meta

    r5333 r5656  
    2828        "entropy-windows.scm"
    2929        "entropy-fixed.scm"
    30         "entropy.scm"
     30        "entropy-parameters.scm"
    3131        "srfi-27-structures.scm"
    3232        "srfi-27-distributions.scm"
  • srfi-27/srfi-27.scm

    r2973 r5656  
    22;;;; Kon Lovett, May '06
    33
    4 (use srfi-27-parameters #;srfi-27-distributions entropy)
     4(use syntax-case lexmod)
     5(use srfi-27-parameters entropy-parameters)
     6
     7;; At this point the default entropy & random source structures are open!
  • srfi-27/srfi-27.setup

    r5147 r5656  
    11(include "setup-header")
    22
    3 (required-extension-version 'lexmod "009")
    4 (required-extension-version 'synch "1.3")
     3(required-extension-version
     4  'lexmod         "009"
     5  'synch          "1.401"
     6  'miscmacros     "2.4")
    57
    6 (install-dynld entropy-structures "2.000" -O3 -d0)
    7 (install-dynld entropy-primitives "2.000" -O3 -d0)
     8(install-dynld entropy-structures "2.1" -O3 -d0)
     9(install-dynld entropy-primitives "2.1" -O3 -d0)
    810
    9 (install-dynld entropy-clock "2.000" -O3 -d0)
     11(install-dynld entropy-clock "2.1" -O3 -d0)
    1012
    1113#+windows
    12 (install-dynld entropy-windows "2.000" -O3 -d0)
     14(install-dynld entropy-windows "2.1" -O3 -d0)
    1315
    1416#+unix
    15 (install-dynld entropy-unix "2.000" -O3 -d0)
     17(install-dynld entropy-unix "2.1" -O3 -d0)
    1618
    17 (install-dynld entropy "2.000")
     19(install-dynld entropy-parameters "2.1")
    1820
    19 (install-dynld srfi-27-structures "2.000")
    20 (install-dynld srfi-27-large-numbers "2.000" -O3 -d0)
     21(install-dynld srfi-27-structures "2.1")
     22(install-dynld srfi-27-large-numbers "2.1" -O3 -d0)
    2123
    22 (install-dynld mrg32k3a-primitives "2.000" -O3 -d0 +easyffi +dollar)
    23 (install-dynld mrg32k3a "2.000")
     24(install-dynld mrg32k3a-primitives "2.1" -O3 -d0 +easyffi +dollar)
     25(install-dynld mrg32k3a "2.1")
    2426
    25 (install-dynld mwc-primitives "2.000" -O3 -d0 +easyffi +dollar)
    26 (install-dynld mwc "2.000")
     27(install-dynld mwc-primitives "2.1" -O3 -d0 +easyffi +dollar)
     28(install-dynld mwc "2.1")
    2729
    28 (install-dynld moa-primitives "2.000" -O3 -d0 +easyffi +dollar)
    29 (install-dynld moa "2.000")
     30(install-dynld moa-primitives "2.1" -O3 -d0 +easyffi +dollar)
     31(install-dynld moa "2.1")
    3032
    31 (install-dynld srfi-27-parameters "2.000")
     33(install-dynld srfi-27-parameters "2.1")
    3234
    33 (install-dynld srfi-27-distributions "2.000")
     35(install-dynld srfi-27-distributions "2.1")
    3436
    35 (install-dynld+docu srfi-27 "2.000")
     37(install-dynld+docu srfi-27 "2.1")
  • srfi-27/tests/conf-test.scm

    r5147 r5656  
    11; Chicken
    22
    3 (use syntax-case lexmod)
    43(use srfi-27)
    54
     
    1211      equal?) ) )
    1312
     13;; Select platform specific entropy source
     14
     15(cond-expand
     16  [windows
     17    (use entropy-windows)
     18    (current-entropy-source-structure crypt-random-entropy) ]
     19  [unix
     20    (use entropy-unix)
     21    (current-entropy-source-structure dev-random-entropy) ]
     22  [else] )
     23
     24;; Say what sources we are using
     25
    1426(newline)
    15 
    16 #;
    17 (print ";Using (current-entropy-source-structure)")
    18 #+windows
    19 (begin
    20   (print ";Using crypt-random-entropy")
    21   (use entropy-windows)
    22   (current-entropy-source-structure crypt-random-entropy) )
    23 #+unix
    24 (begin
    25   (print ";Using dev-random-entropy")
    26   (use entropy-unix)
    27   (current-entropy-source-structure dev-random-entropy) )
    28 
    29 #;(print ";Using (current-random-source-structure)")
    30 #;(lexmod-open (current-random-source-structure))
    31 
    32 (print ";Using MRG32k3a")
    33 (use mrg32k3a)
    34 (lexmod-open MRG32k3a)
    35 
     27(print "Entropy Source = " (entropy-kind))
     28(print " Random Source = " (random-source-kind default-random-source))
    3629(newline)
     30
    3731
    3832; CONFIDENCE TESTS FOR SRFI-27 "Sources of Random Bits"
     
    128122       (n 1 (* n 2)))
    129123      ((fx> k 1024))
    130     ;(display k)
    131     ;(display " ")
     124    (display k)
     125    (display " ")
    132126    (my-random-integer n))
    133127  (print "ok")
Note: See TracChangeset for help on using the changeset viewer.