From 6a5488b1d3966452daa4f6d1f025bc22f4b02566 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 13 Jul 2021 21:08:35 -0700 Subject: rand: support buffers as random seeds. * rand.c (make_random_state): Recognize buffer object as sources of bits for seeding. * tests/013/rand.tl: New file. * txr.1: Documented. --- tests/013/rand.tl | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/013/rand.tl (limited to 'tests/013/rand.tl') diff --git a/tests/013/rand.tl b/tests/013/rand.tl new file mode 100644 index 00000000..f593c39c --- /dev/null +++ b/tests/013/rand.tl @@ -0,0 +1,84 @@ +(load "../common") + +(mtest + (random-state-get-vec (make-random-state #b'' 0)) + #(740765398 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #b'FF' 0)) + #(4278190080 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #b'FFFF' 0)) + #(4294901760 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #b'FFFFFF' 0)) + #(4294967040 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #b'FFFFFFFF' 0)) + #(4294967295 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #b'FFFFFFFFFF' 0)) + #(4294967295 4278190080 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state (make-buf (* 4 16) #xff) 0)) + #(4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 0) + (random-state-get-vec (make-random-state (make-buf (* 5 16) #xff) 0)) + #(4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 0)) + +(mtest + (random-state-get-vec (make-random-state 0 0)) + #(740765398 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #xFF 0)) + #(255 1304255849 3309840409 338361566 4155223728 1162561521 4236628653 + 446542199 639181595 1801947880 2890206840 2695457564 2292665861 + 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #xFFFF 0)) + #(65535 1304255849 3309840409 338361566 4155223728 1162561521 4236628653 + 446542199 639181595 1801947880 2890206840 2695457564 2292665861 + 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #xFFFFFF 0)) + #(16777215 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #xFFFFFFFF 0)) + #(4294967295 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state #xFFFFFFFFFF 0)) + #(4294967295 255 3309840409 338361566 4155223728 1162561521 4236628653 + 446542199 639181595 1801947880 2890206840 2695457564 2292665861 + 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state (expt 2 (* 8 4 16)) 0)) + #(740765398 1304255849 3309840409 338361566 4155223728 1162561521 + 4236628653 446542199 639181595 1801947880 2890206840 2695457564 + 2292665861 3251351234 2171649709 704313206 0) + (random-state-get-vec (make-random-state (pred (expt 2 (* 8 4 16))) 0)) + #(4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 0) + (random-state-get-vec (make-random-state (pred (expt 2 (* 8 4 17))) 0)) + #(4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 4294967295 4294967295 + 4294967295 4294967295 4294967295 4294967295 0)) + +(mtest + (random-state-get-vec (make-random-state + #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))) + #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + (random-state-get-vec (make-random-state + #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17))) + #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17) + (random-state-get-vec (make-random-state + #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17) 10)) + #(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17)) -- cgit v1.2.3