From 94f3524a314aa2fe0d1e30edbe48ff878de4cdf5 Mon Sep 17 00:00:00 2001 From: Marco Baringer Date: Tue, 24 Jan 2006 13:17:28 +0100 Subject: [PATCH] Added gen-float --- src/random.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/random.lisp b/src/random.lisp index f5a1526..1a1392c 100644 --- a/src/random.lisp +++ b/src/random.lisp @@ -120,6 +120,26 @@ returning true. This second run limit prevents that.") (min (1- most-negative-fixnum))) (+ min (random (1+ (- max min))))) +(defgenerator gen-float (&key bound (type 'short-float)) + (let* ((most-negative (ecase type + (short-float most-negative-short-float) + (single-float most-negative-single-float) + (double-float most-negative-double-float) + (long-float most-negative-long-float))) + (most-positive (ecase type + (short-float most-positive-short-float) + (single-float most-positive-single-float) + (double-float most-positive-double-float) + (long-float most-positive-long-float))) + (bound (or bound (max most-positive (- most-negative))))) + (coerce + (ecase (random 2) + (0 ;; generate a positive number + (random (min most-positive bound))) + (1 ;; generate a negative number + (- (random (min (- most-negative) bound))))) + type))) + (defgenerator gen-character (&key (code (gen-integer :min 0 :max (1- char-code-limit))) (alphanumericp nil)) (if alphanumericp -- 1.7.10.4