count objects in a list and random numb gen
Tim Roberts
timr at probo.com
Fri Jan 9 20:53:21 EST 2004
Bart Nessux <bart_nessux at hotmail.com> wrote:
>
>Also, does this bit of code look to be truely random?
The code doesn't look random at all, but of course that's not really the
question you meant to ask.
>def random_number_gen():
> winner = []
> winner.append(random.sample(xrange(100000), 1))
> print winner
It depends entirely on your definition of "truly random". There is no
single definition of that phrase.
However, that specific example provides no benefit over this simpler and
more efficient code:
def random_number_gen():
print int(random.uniform(0,100000))
which is itself just a shortcut for:
def random_number_gen():
print int(random.random()*100000))
What are you using the random numbers for? Tell us what you want to do
with them, and we'll suggest the right method.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list