Re: Random Number Generation Issues

2008-12-26 Thread Mark H.
On Dec 23, 3:10 pm, Jason wrote: > For the time-being, you could try something like: > > user> (def *random* (java.util.Random.)) > #'user/*random* > > user> (defn my-rand-int [max-val] >         (let [bit-length (.bitLength (BigInteger. (str max-val)))] >           (loop [] >             (let [x

Re: Random Number Generation Issues

2008-12-23 Thread Michael Wood
On Wed, Dec 24, 2008 at 1:17 AM, Randall R Schulz wrote: > > On Tuesday 23 December 2008 15:15, Randall R Schulz wrote: >> ... >> >> I tried 20 times with the same result each time. If you increase the >> range much beyond MAX_VALUE, you start to get the repeats and then >> the monotonically incr

Re: Random Number Generation Issues

2008-12-23 Thread Randall R Schulz
On Tuesday 23 December 2008 15:15, Randall R Schulz wrote: > ... > > I tried 20 times with the same result each time. If you increase the > range much beyond MAX_VALUE, you start to get the repeats and then > the monotonically increasing property ceases to hold, though > monotonically non-decreasi

Re: Random Number Generation Issues

2008-12-23 Thread Randall R Schulz
On Tuesday 23 December 2008 14:44, Chris Bunch wrote: > I've got the newest version of Clojure and wrote a simple program to > generate a list of 100 random numbers, but I seem to get a lot of > duplicate numbers (especially when I pick a large upper bound for > rand-int). My code is pretty simila

Re: Random Number Generation Issues

2008-12-23 Thread Jason
By the way, here's the code from clojure.core: (defn rand "Returns a random floating point number between 0 (inclusive) and 1 (exclusive)." ([] (. Math (random))) ([n] (* n (rand (defn rand-int "Returns a random integer between 0 (inclusive) and n (exclusive)." [n] (int (rand n))

Re: Random Number Generation Issues

2008-12-23 Thread Jason
> (defn gen-rands [max-val] ... By the way, you could shorten this to: (defn gen-rands [max-val] (take 100 (repeatedly #(rand-int max-val > Is there anything I've done wrong that would result in me getting > 2147483647 so many times? Thanks in advance! rand-int says it returns "an integ

Re: Random Number Generation Issues

2008-12-23 Thread Randall R Schulz
On Tuesday 23 December 2008 14:44, Chris Bunch wrote: > I've got the newest version of Clojure and wrote a simple program to > generate a list of 100 random numbers, but I seem to get a lot of > duplicate numbers (especially when I pick a large upper bound for > rand-int). My code is pretty simila

Random Number Generation Issues

2008-12-23 Thread Chris Bunch
I've got the newest version of Clojure and wrote a simple program to generate a list of 100 random numbers, but I seem to get a lot of duplicate numbers (especially when I pick a large upper bound for rand-int). My code is pretty similar to an example in the Programming Clojure book: (defn ge