Whrandom

Tim Hochberg tim.hochberg at ieee.org
Mon May 14 15:32:11 EDT 2001


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





"Stephen Hansen" <news at myNOSPAM.org> wrote in message
news:95WL6.30870$154.8679563 at typhoon.we.rr.com...
>     You'll need to call whrandom.randint five times. Some of the
> possibilities are:
>
> nums = []
> for i in range(0, 5):
>     nums.append(whrandom.randint(1, 1000))
>
> or
>
> nums = [whrandom.randint(1, 1000) for i in range(1, 1000)]
>
> The latter bit is a list comprehension, so will only work in 2.0+. (I
> believe.. then again, I never paid any attention to what was available in
> 1.6 since 2.0beta came out the same day. *grin*)
>
> --S
> "Oskar Stefan" <st.oskar at vol.at> wrote in message
> news:9dp9md$bc0$1 at newsreaderg1.core.theplanet.net...
> > Hello!
> >
> > Could anyone give me an Example how can
> > I create 5 Random numbers between 1 and 1000.
> > I know this goes with whrandom but I
> > become only one number when I write whrandom.randint(1,1000)
> > but I will have 5 numbers between 1 and 1000 but no number
> > several times.
> >
> > thanks for your help
> >
> > osi
>
>





More information about the Python-list mailing list