[Tutor] ** Newbie ** - Fastest random choice from integers 0 to
X?
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Thu, 7 Feb 2002 21:56:01 -0800 (PST)
On Thu, 7 Feb 2002, Remco Gerlich wrote:
> > My guess is:
> >
> > random.randrange( 0, (X+1), 1 )
> >
> > Is this right?
>
> Yes.
>
> Apart from the speed, it's about the only right way, since this is a
> standard library function for it, and the other one, random.randint,
> is deprecated (shouldn't be used anymore).
Also, the third parameter --- the "step" --- is set to 1 by default, so
you can simplify your call to:
random.randrange(0, X+1)
Good luck to you!