summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-10-20 15:57:35 +0200
committerLudovic Courtès <ludo@gnu.org>2020-10-20 16:30:16 +0200
commitccf3dcba3dbddd4fd8daf0b5641ba997de12647a (patch)
tree417f1a9fb2428fa83fd28cf70bff9b8f6633c7b6
parentf59ec1de9494a3c6c571d573b450d87b8044d4bf (diff)
tests: Do not fetch and print the random seed from the top level.
* guix/tests.scm (%seed): Turn into a memoizing procedure. (random-text, random-bytevector): Adjust accordingly.
-rw-r--r--guix/tests.scm10
1 files changed, 6 insertions, 4 deletions
diff --git a/guix/tests.scm b/guix/tests.scm
index 3ccf049a7d..fc3d521163 100644
--- a/guix/tests.scm
+++ b/guix/tests.scm
@@ -160,15 +160,17 @@ too expensive to build entirely in the test store."
number->string)
(logxor (getpid) (car (gettimeofday)))))
-(define %seed
+(define (%seed)
(let ((seed (random-seed)))
(format (current-error-port) "random seed for tests: ~a~%"
seed)
- (seed->random-state seed)))
+ (let ((result (seed->random-state seed)))
+ (set! %seed (lambda () result))
+ result)))
(define (random-text)
"Return the hexadecimal representation of a random number."
- (number->string (random (expt 2 256) %seed) 16))
+ (number->string (random (expt 2 256) (%seed)) 16))
(define (random-bytevector n)
"Return a random bytevector of N bytes."
@@ -176,7 +178,7 @@ too expensive to build entirely in the test store."
(let loop ((i 0))
(if (< i n)
(begin
- (bytevector-u8-set! bv i (random 256 %seed))
+ (bytevector-u8-set! bv i (random 256 (%seed)))
(loop (1+ i)))
bv))))