From d5169d56278dc7d663327c71cd79dea5dbe97309 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 21 Feb 2017 21:38:26 -0800 Subject: [PATCH] Implement random-byte-vector in Edwin. --- src/edwin/edwin.pkg | 1 + src/edwin/string.scm | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/edwin/edwin.pkg b/src/edwin/edwin.pkg index 9f3844ebc..aba9dd98a 100644 --- a/src/edwin/edwin.pkg +++ b/src/edwin/edwin.pkg @@ -168,6 +168,7 @@ USA. list->string make-string make-vector-8b + random-byte-vector reverse-string reverse-string! reverse-substring diff --git a/src/edwin/string.scm b/src/edwin/string.scm index a4b599a6f..61256efc1 100644 --- a/src/edwin/string.scm +++ b/src/edwin/string.scm @@ -588,6 +588,14 @@ USA. (char-set? object) (unary-procedure? object))) +(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))) -- 2.25.1