Verified Commit 3747e18b authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Make RANDOM generate floats correctly

parent b975f7d7
......@@ -109,7 +109,10 @@
`(/ (log ,n) (log ,base))))
(sqrt (n) `((@ *math sqrt) ,n))
(random (&optional upto) (if upto
`(floor (* ,upto (random)))
(maybe-once-only (upto)
`(if (rem ,upto 1)
(* ,upto (random))
(floor (* ,upto (random)))))
'(funcall (@ *math random)))))
(defpsmacro ash (integer count)
......
......@@ -868,3 +868,21 @@
"odd"))
(bar 9))
"odd")
(test-js-eval random-float-const
(< 0 (rem (random 123.456) 1) 1)
t)
(test-js-eval random-int-const
(rem (random 234) 1)
0)
(test-js-eval random-float-fun-once-only
(let ((x t))
(flet ((foo ()
(prog1 (if x
123.123
(throw "foobar"))
(setf x nil))))
(< 0 (rem (random (foo)) 1) 1)))
t)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment