Implement random-bytevector.
authorChris Hanson <org/chris-hanson/cph>
Wed, 22 Feb 2017 05:22:51 +0000 (21:22 -0800)
committerChris Hanson <org/chris-hanson/cph>
Wed, 22 Feb 2017 05:22:51 +0000 (21:22 -0800)
src/runtime/random.scm
src/runtime/runtime.pkg

index cf7e18df091e96d4fcd879ca0f9f0bcf4d4767e1..d63520d30f8a3fb8fffcded596a7edda3e4e9913 100644 (file)
@@ -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)
index 24f56cd4e103bdaf4e07e645844f99cdda338cef..5fdac0ab2cb96735b0af39ea23bb622b5c56f989 100644 (file)
@@ -4055,6 +4055,7 @@ USA.
          make-random-state
          random
          random-byte-vector
+         random-bytevector
          random-integer
          random-real
          random-source-make-integers