Whrandom
Joshua Marshall
jmarshal at mathworks.com
Mon May 14 16:40:38 EDT 2001
Tim Hochberg <tim.hochberg at ieee.org> wrote:
> I think the original poster wanted no numbers repeated. If that's the case,
> the following modification of Stephen's code should do the trick:
> nums = []
> while len(nums) < 5:
> r = whrandom.randint(1,1000)
> if r not in nums:
> nums.append(r)
> I'm not a statistician, but I believe that this doesn't screw up the
> distributions....
> -tim
Another approach--more wasteful (almost certainly), but with some merit:
nums = range(1,1001)
from random import shuffle
shuffle(nums)
print nums[:5]
More information about the Python-list
mailing list