From 465e540267d5f38a73aa958c817d8652cdf2addb Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 21 Feb 2017 21:22:51 -0800 Subject: [PATCH] Implement random-bytevector. --- src/runtime/random.scm | 8 ++++++++ src/runtime/runtime.pkg | 1 + 2 files changed, 9 insertions(+) diff --git a/src/runtime/random.scm b/src/runtime/random.scm index cf7e18df0..d63520d30 100644 --- a/src/runtime/random.scm +++ b/src/runtime/random.scm @@ -174,6 +174,14 @@ USA. (vector-8b-set! s i (small-random-integer 256 state))) s)) +(define (random-bytevector n #!optional state) + (let ((state (get-random-state state 'random-bytevector)) + (bytes (make-bytevector n))) + (do ((i 0 (fix:+ i 1))) + ((fix:= i n)) + (bytevector-u8-set! bytes i (small-random-integer #x100 state))) + bytes)) + (define (random-source-make-integers source) (guarantee-random-state source 'RANDOM-SOURCE-MAKE-INTEGERS) (lambda (modulus) diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 24f56cd4e..5fdac0ab2 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -4055,6 +4055,7 @@ USA. make-random-state random random-byte-vector + random-bytevector random-integer random-real random-source-make-integers -- 2.25.1