Implement random-byte-vector in Edwin.
authorChris Hanson <org/chris-hanson/cph>
Wed, 22 Feb 2017 05:38:26 +0000 (21:38 -0800)
committerChris Hanson <org/chris-hanson/cph>
Wed, 22 Feb 2017 05:38:26 +0000 (21:38 -0800)
src/edwin/edwin.pkg
src/edwin/string.scm

index 9f3844ebcfaa5cfd4f8478b7260714007d8f654d..aba9dd98ade722e5a4f7033b8e9e8dc896398334 100644 (file)
@@ -168,6 +168,7 @@ USA.
          list->string
          make-string
          make-vector-8b
+         random-byte-vector
          reverse-string
          reverse-string!
          reverse-substring
index a4b599a6fcbeb2823c5abc6f801e686500743a01..61256efc160245b2cbe4c9f9f775df9fc9ff8499 100644 (file)
@@ -588,6 +588,14 @@ USA.
       (char-set? object)
       (unary-procedure? object)))
 \f
+(define (random-byte-vector n #!optional state)
+  (let ((bv (random-bytevector n state))
+       (s (make-vector-8b n)))
+    (do ((i 0 (fix:+ i 1)))
+       ((not (fix:< i n)))
+      (vector-8b-set! s i (bytevector-u8-ref bv i)))
+    s))
+
 (define (vector-8b->hexadecimal bytes)
   (define-integrable (hex-char k)
     (string-ref "0123456789abcdef" (fix:and k #x0F)))