RE: RandRange ain't so Random
Graphing this to indulge morbid curiosity I used the following code and came up with a pretty even distribution after 1,000,000 iterations. chartheight="350" format="flash" showlegend="no" show3d="no" scalefrom="0" xaxistitle="Week Of Year" yaxistitle="Number of Items"> seriescolor="##FF" markerstyle="none"> > -Original Message- > From: Joe Rinehart [mailto:[EMAIL PROTECTED] > Sent: 23 August 2004 20:42 > To: CF-Talk > Subject: Re: RandRange ain't so Random > > Waiting for a phone call, I ran a test pulling a random number between > 1 and 26 inclusive 100,000 times, and the distribution across > the range was very near even. Here's code: > > > > > > > > > > > > > > > > Even distribution: #10 / size# > > #i# - #count[i]# > > > > -joe > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: RandRange ain't so Random
Samuel R. Neff wrote: > You're better off not calling randomize() at all. If you don't call it, > then CF will default to the calling randomize() with the current time in > milliseconds. However, due to argument types you can't actually pass that > level of precision to randomize() yourself. Okay. I'd not used random functions in a while, and had forgotten whether CF seeded that way or not. > To get truly random numbers across requests, your best bet is to create an > instance of java.util.Random and store it in the Application scope. To nitpick: to get truly random numbers, use a quantum source, like radioactive decay. Although I agree that that's a good way to get the most out of the pseudorandom number generator. --Ben [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: RandRange ain't so Random
You're better off not calling randomize() at all. If you don't call it, then CF will default to the calling randomize() with the current time in milliseconds. However, due to argument types you can't actually pass that level of precision to randomize() yourself. To get truly random numbers across requests, your best bet is to create an instance of java.util.Random and store it in the Application scope. More info here: http://www.markme.com/cantrell/archives/004256.cfm HTH, Sam Blog http://www.rewindlife.com TeamMM http://www.macromedia.com/go/team > -Original Message- > From: Ben Doom [mailto:[EMAIL PROTECTED] > Sent: Monday, August 23, 2004 3:33 PM > To: CF-Talk > Subject: Re: RandRange ain't so Random > > Running a quick test, I'm finding (on CF 6.1) that after runing > randomize(timeformat(now(), "ss")) (which, btw, is not a great sample > set) that I routinely get a reasonable even sample. > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: RandRange ain't so Random
Waiting for a phone call, I ran a test pulling a random number between 1 and 26 inclusive 100,000 times, and the distribution across the range was very near even. Here's code: Even distribution: #10 / size# #i# - #count[i]# -joe [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: RandRange ain't so Random
Running a quick test, I'm finding (on CF 6.1) that after runing randomize(timeformat(now(), "ss")) (which, btw, is not a great sample set) that I routinely get a reasonable even sample. That is, for a run of 1, randramge(1,25) returns each number at least 350-ish times and no more than 450-ish times. Note that I'm not really applying any mathematical sense of random, just a common-sense one. --Ben S. Isaac Dealey wrote: >> > > >>Seems "weighted" towards the numbers in the middle more. >>So, how can I >>make this a little more random? > > > How'd you test that theory? ... How large was your sample? The sample > size needs to be in the tens to hundreds of thousands at least to be > sure you're not just seeing the random weighting you'd get from a > small sample. Law of large numbers and all that... iirc... > > s. isaac dealey 954.927.5117 > > new epoch : isn't it time for a change? > > add features without fixtures with > the onTap open source framework > http://www.sys-con.com/story/?storyid=44477&DE=1 > http://www.sys-con.com/story/?storyid=45569&DE=1 > http://www.fusiontap.com > > > > > [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: RandRange ain't so Random
> > Seems "weighted" towards the numbers in the middle more. > So, how can I > make this a little more random? How'd you test that theory? ... How large was your sample? The sample size needs to be in the tens to hundreds of thousands at least to be sure you're not just seeing the random weighting you'd get from a small sample. Law of large numbers and all that... iirc... s. isaac dealey 954.927.5117 new epoch : isn't it time for a change? add features without fixtures with the onTap open source framework http://www.sys-con.com/story/?storyid=44477&DE=1 http://www.sys-con.com/story/?storyid=45569&DE=1 http://www.fusiontap.com [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: RandRange ain't so Random
> Seems "weighted" towards the numbers in the middle more. How did you test that? Does/would using randomize() before you call randRange() have an impact on your results? -- Marc [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]