mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-09 05:57:36 +02:00
parent
72a9782c80
commit
09221ec87d
2 changed files with 23 additions and 4 deletions
|
@ -58,10 +58,9 @@ static sexp sexp_rs_random_integer (sexp ctx, sexp self, sexp_sint_t n, sexp rs,
|
|||
sexp_call_random(rs, m);
|
||||
data[i] = m;
|
||||
}
|
||||
sexp_call_random(rs, m);
|
||||
mod = sexp_bignum_data(bound)[hi-1] * sizeof(int32_t) / sizeof(sexp_uint_t);
|
||||
if (mod)
|
||||
data[i] = m % mod;
|
||||
mod = sexp_bignum_data(bound)[hi-1];
|
||||
if (mod && sexp_bignum_data(res)[hi-1] > 0)
|
||||
sexp_bignum_data(res)[hi-1] %= mod;
|
||||
#endif
|
||||
} else {
|
||||
res = sexp_type_exception(ctx, self, SEXP_FIXNUM, bound);
|
||||
|
|
20
tests/srfi-27-tests.scm
Normal file
20
tests/srfi-27-tests.scm
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
(import (scheme base)
|
||||
(srfi 27)
|
||||
(chibi test))
|
||||
|
||||
(test-begin "srfi-27")
|
||||
|
||||
(define (test-random rand n)
|
||||
(test-assert (<= 0 (rand n) (- n 1))))
|
||||
|
||||
(let ((rs (make-random-source)))
|
||||
;; chosen by fair dice roll. guaranteed to be random
|
||||
(random-source-pseudo-randomize! rs 4 4)
|
||||
(let ((rand (random-source-make-integers rs)))
|
||||
(do ((k 0 (+ k 5))
|
||||
(n 1 (* n 2)))
|
||||
((> k 1024))
|
||||
(test-random rand n))))
|
||||
|
||||
(test-end)
|
Loading…
Add table
Reference in a new issue