From: Adam Sanderson Date: 2005-07-18T04:20:55+09:00 Subject: Re: Sampling (#39) Here is my sample, it sounds like some other folks did a moving window like this, and that some people also thought it wasn't truly random. As far as I'm concerned, it's random enough ;) This was a fairly fun quiz. I was thinking of also trying to do something along the lines of picking a random number within the range, and then picking from within the resulting ranges. It would avoid one having to sort the results, and you wouldn't get collisions. Maybe I'll whip it up later. ------------------------------------------------ Tiny bit of code ------------------------------------------------ # Moving window Sample # Adam Sanderson max = ARGV.pop.to_i samples = ARGV.pop.to_i step = max / samples min = -step samples.times{ puts( (min += step) + rand(step) ) } ------------------------------------------------ Results ------------------------------------------------ netghost@mu /cygdrive/c/Projects $ time ruby number_sample.rb 5_000_000 1_000_000_000 > num_res.txt real 0m36.757s user 0m0.015s sys 0m0.000s netghost@mu /cygdrive/c/Projects $ tail num_res.txt 999998016 999998349 999998503 999998767 999998840 999999156 999999281 999999530 999999779 999999987 netghost@mu /cygdrive/c/Projects $ head num_res.txt 40 263 560 640 925 1003 1288 1428 1626 1901