-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathiff-rand.scm
38 lines (32 loc) · 1.03 KB
/
iff-rand.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;; integer finite functions test
(import (owl iff))
(import (owl random))
(define-syntax lets (syntax-rules () ((lets . stuff) (let* . stuff)))) ; TEMP
(define max-bits 1024)
(define max-nums 100)
(define rst
(seed->rands (time-ms)))
(define (test rst)
(lets
((rst shift (rand rst max-bits))
(rst nnums (rand rst max-nums))
(nnums (max 1 nnums))
(rst nums (random-numbers rst (<< 1 shift) (max 1 nnums)))
;(_ (print nums))
(pairs (map cons nums (lrange 0 1 nnums)))
(iff (fold (λ (iff pair) (iput iff (car pair) (cons (cdr pair) (iget iff (car pair) null)))) #empty pairs))
(ok
(fold
(λ (iff pair)
(lets
((key val pair)
(stored (iget iff key null)))
(if (has? stored val)
iff
(error "Not there: " val))))
iff pairs)))
(if ok rst 'bug)))
(let loop ((rst rst) (n 0))
(print n)
(if (< n 20)
(loop (test rst) (+ n 1))))