use a better random number generator from CHICKEN
This commit is contained in:
parent
dd1f97484a
commit
1fb756d647
|
@ -3,16 +3,12 @@
|
||||||
guess-sentence
|
guess-sentence
|
||||||
generate-next-word
|
generate-next-word
|
||||||
join-verses
|
join-verses
|
||||||
%random-seed
|
|
||||||
seed-from-entropy)
|
seed-from-entropy)
|
||||||
(import scheme (chicken base) srfi-69
|
(import scheme (chicken base) srfi-69
|
||||||
(chicken format)
|
(chicken format)
|
||||||
(chicken random)
|
(chicken random))
|
||||||
srfi-4)
|
|
||||||
(define (seed-from-entropy)
|
(define (seed-from-entropy)
|
||||||
(let ((bytes (blob->u8vector (random-bytes))))
|
(set-pseudo-random-seed! (random-bytes)))
|
||||||
(set! %random-seed (+ (u8vector-ref bytes 0)
|
|
||||||
(* 255 (u8vector-ref bytes 1))))))
|
|
||||||
(define (join-verses* lst str book chapter verse)
|
(define (join-verses* lst str book chapter verse)
|
||||||
(if (null? lst)
|
(if (null? lst)
|
||||||
str
|
str
|
||||||
|
|
|
@ -169,15 +169,17 @@
|
||||||
|
|
||||||
;;; Lehmer random number generator
|
;;; Lehmer random number generator
|
||||||
|
|
||||||
(define %random-seed 10000)
|
(cond-expand
|
||||||
|
(chicken (import (chicken random))
|
||||||
(define random
|
(define random generate-random-real))
|
||||||
(let ((m 65537)
|
(else (define %random-seed 10000)
|
||||||
(a 75))
|
(define random
|
||||||
(lambda ()
|
(let ((m 65537)
|
||||||
(set! %random-seed (remainder (* a %random-seed)
|
(a 75))
|
||||||
m))
|
(lambda ()
|
||||||
(/ %random-seed (- m 1)))))
|
(set! %random-seed (remainder (* a %random-seed)
|
||||||
|
m))
|
||||||
|
(/ %random-seed (- m 1)))))))
|
||||||
|
|
||||||
(define probability-list->guess
|
(define probability-list->guess
|
||||||
(lambda (lst normalized-random-number)
|
(lambda (lst normalized-random-number)
|
||||||
|
|
11
toplevel.scm
11
toplevel.scm
|
@ -37,10 +37,13 @@
|
||||||
(thread-sleep! time)
|
(thread-sleep! time)
|
||||||
(cond
|
(cond
|
||||||
((equal? previous-word "startofbook")
|
((equal? previous-word "startofbook")
|
||||||
(printf "THE BOOK OF ~A~%~%~%" (generate-next-word table "of"))
|
(let ((next-word (generate-next-word table "of")))
|
||||||
(printf "~A:1:1" (+ book 1))
|
(if (equal? next-word "the")
|
||||||
(generate-continuously* (generate-next-word table "startofverse")
|
(set! next-word (generate-next-word table "the")))
|
||||||
time (+ 1 book) 1 1))
|
(printf "THE BOOK OF ~A~%~%~%" next-word)
|
||||||
|
(printf "~A:1:1" (+ book 1))
|
||||||
|
(generate-continuously* (generate-next-word table "startofverse")
|
||||||
|
time (+ 1 book) 1 1)))
|
||||||
((equal? previous-word "startofchapter")
|
((equal? previous-word "startofchapter")
|
||||||
(printf "~%~%~A:~A:1" book (+ 1 chapter))
|
(printf "~%~%~A:~A:1" book (+ 1 chapter))
|
||||||
(generate-continuously* (generate-next-word table "startofverse")
|
(generate-continuously* (generate-next-word table "startofverse")
|
||||||
|
|
Loading…
Reference in New Issue