"R. Joseph Newton" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I'm wondering if there is an issue with the random function in terms of scaling. I > have been testing a merge sort, and I noticed that when my test, built by pushing rand(100000) a given number of times into it, starts getting much higher than 10,000 items, the rnadom numbers start clumping. > > Just in case it was my sort that was the problem, I substituted the built-in sort, > which does perform considerably faster, but renders the same effect. to test the algorithm, I print out the first 30 elements: > > 12.20703125 > 21.3623046875 > 21.3623046875 > 42.724609375 > 61.03515625 > 76.2939453125 > 91.552734375 > 94.6044921875 > 106.8115234375 > 106.8115234375 > 112.9150390625 > 115.966796875 > 125.1220703125 > 128.173828125 > 143.4326171875 > 155.6396484375 > 167.8466796875 > 170.8984375 > 192.2607421875 > 195.3125 > 213.623046875 > 213.623046875 > 228.8818359375 > 250.244140625 > 286.865234375 > 286.865234375 > 289.9169921875 > 357.0556640625 > 369.2626953125 > 390.625 > [snip data] > > Needless to say, that is a lot of . Is there any alternativcollisionse random > function that provides greater variation?
Hi Joseph. Careful inspection shows that each of your random numbers is exactly divisible by 3.0517578125. Dividing your range of 100000 by this figure (magically, for those who know their powers of two) gives 32768, showing that 'rand' is in fact producing a 15-bit pseudo-random number scaled according to the range that you supply. As Todd says, there is a Math::TrulyRandom module, but I believe it runs only on Unix (I believe you're on WinNT?). A quick search shows that there are several random number routines, notably Data::Random, which may provide what you need. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
