Skip to content
Browse files

Add random to processing/math

  • Loading branch information...
1 parent b30dd95 commit d789fdd9c28038c8153ae89a34eded3f9e751bf7 @dharmatech committed Mar 8, 2010
Showing with 19 additions and 5 deletions.
  1. +19 −5 processing/math.sls
View
24 processing/math.sls
@@ -1,15 +1,29 @@
-(library
+(library (agave processing math)
- (agave processing math)
+ (export map-number random)
- (export map-number)
-
- (import (rnrs))
+ (import (rnrs)
+ (srfi :27 random-bits))
(define (map-number value low1 high1 low2 high2)
(+ low2
(* (/ (- value low1)
(- high1 low1))
(- high2 low2))))
+
+ (define random
+ (case-lambda
+ ((a b)
+ (cond ((and (integer? a)
+ (integer? b))
+ (+ a (random-integer (- b a))))
+ (else
+ (+ a (* (- b a)
+ (random-real))))))
+ ((a)
+ (cond ((integer? a) (random 0 a))
+ (else (random 0.0 a))))
+ (() (random-real))))
+
)

0 comments on commit d789fdd

Please sign in to comment.
Something went wrong with that request. Please try again.