From: Marco Baringer Date: Tue, 24 Jan 2006 12:17:28 +0000 (+0100) Subject: Added gen-float X-Git-Url: http://repo.macrolet.net/gitweb/?p=fiveam.git;a=commitdiff_plain;h=94f3524a314aa2fe0d1e30edbe48ff878de4cdf5 Added gen-float --- 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