Changeset 35473 in project


Ignore:
Timestamp:
04/29/18 16:18:57 (4 months ago)
Author:
kon
Message:

fix make reals type, add type for clock entropy

Location:
release/4/srfi-27/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/srfi-27/trunk/entropy-clock.scm

    r34208 r35473  
    77  make-entropy-source-system-clock)
    88
    9 (import scheme)
    10 
    11 (import chicken foreign)
     9(import scheme chicken foreign)
    1210
    1311(use entropy-source entropy-support)
     
    1816#include <time.h>
    1917#include <math.h>
    20 
    21 static double
    22 f64init()
    23 {
    24   return (double) time( NULL );
    25 }
    26 
    27 static double
    28 f64rand( double f64seed )
    29 {
    30   double x = 11.0 + (25214903917.0 * f64seed);
    31   return fmod( x, 281474976711000.0 ); /* actually remainder */
    32 }
     18/* linear congruential generator */
     19#define MULTIPLIER  25214903917.0
     20#define LIMITER     81474976711000.0
    3321<#
    3422
    35 (define f64init (foreign-lambda double "f64init"))
    36 (define f64rand (foreign-lambda double "f64rand" double))
     23(define f64init (foreign-lambda* double ()
     24  "C_return( (double) time( NULL ) );"))
     25
     26(define f64rand (foreign-lambda* double ((double f64seed))
     27  "double x = 11.0 + (MULTIPLIER * f64seed);
     28  C_return( fmod( x, LIMITER ) );"))
     29
     30;;;
     31
     32(include "srfi-27-common-types")
    3733
    3834;;; Entropy from system clock
    3935
     36(: make-entropy-source-system-clock (--> entropy-source))
     37;
    4038(define (make-entropy-source-system-clock)
    41   (let* ((f64seed (f64init) )
    42          (_f64rand
    43           (lambda ()
    44             (set! f64seed (f64rand f64seed))
    45             f64seed ) ) )
     39  (let* (
     40    (*f64seed* (f64init))
     41    (*f64rand*
     42      (lambda ()
     43        (set! *f64seed* (f64rand *f64seed*))
     44        *f64seed*)) )
    4645    (*make-entropy-source
    4746      ;
     
    5352      ;
    5453      (lambda ()
    55         (make-entropic-u8/f64 _f64rand) )
     54        (make-entropic-u8/f64 *f64rand*) )
    5655      ;
    57       _f64rand
     56      *f64rand*
    5857      ;
    5958      (lambda (u8cnt u8vec)
    60         (entropic-u8vector-filled/f64 u8cnt u8vec _f64rand) )
     59        (entropic-u8vector-filled/f64 u8cnt u8vec *f64rand*) )
    6160      ;
    6261      (lambda (f64cnt f64vec)
    63         (entropic-f64vector-filled f64cnt f64vec _f64rand) ) ) ) )
     62        (entropic-f64vector-filled f64cnt f64vec *f64rand*) ) ) ) )
    6463
    6564(register-entropy-source! 'system-clock make-entropy-source-system-clock)
  • release/4/srfi-27/trunk/srfi-27.scm

    r35456 r35473  
    4646  entropy-source-f64vector
    4747  ;;
    48   current-random-integer
    49   current-random-real)
     48  random-integer/current
     49  random-real/current)
    5050
    5151(import scheme chicken)
     
    216216  ((@random-source-make-integers (current-random-source))) )
    217217
    218 (: current-random-integer (deprecated current-random-integer))
    219 (define current-random-integer current-random-integer)
    220 
    221218(: current-random-real (--> float))
    222219;
    223220(define (current-random-real)
    224221  ((@random-source-make-reals (current-random-source)) #f) )
    225 
    226 (: current-random-real (deprecated current-random-real))
    227 (define current-random-real current-random-real)
    228222
    229223(: make-random-source (#!optional random-source --> random-source))
     
    323317  ((@random-source-make-integers (check-random-source 'random-source-make-integers rs))) )
    324318
    325 (: random-source-make-integers (random-source #!optional fixnum --> random-real-function))
     319(: random-source-make-reals (random-source #!optional fixnum --> random-real-function))
    326320;
    327321(define (random-source-make-reals rs #!optional prec)
     
    342336    (and prec (check-real-precision 'random-source-make-f64vectors prec 'precision))) )
    343337
     338;;;
     339
     340(: random-integer/current (deprecated current-random-integer))
     341(define random-integer/current current-random-integer)
     342
     343(: random-real/current (deprecated current-random-real))
     344(define random-real/current current-random-real)
     345
    344346) ;module srfi-27
  • release/4/srfi-27/trunk/tests/srfi-27-test.scm

    r34967 r35473  
    4848  (test-assert (->string (random-source-kind (current-random-source))) #t)
    4949  (test-assert (procedure? random-integer))
     50  (test-assert (random-integer 5))
    5051  (test-assert (procedure? random-real))
     52  (test-assert (random-real))
    5153)
    5254
Note: See TracChangeset for help on using the changeset viewer.