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