From: Chris Hanson Date: Wed, 22 Feb 2017 05:22:51 +0000 (-0800) Subject: Implement random-bytevector. X-Git-Tag: mit-scheme-pucked-9.2.12~220^2~27 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=465e540267d5f38a73aa958c817d8652cdf2addb;p=mit-scheme.git Implement random-bytevector. --- 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