JoanCarles p Casasín
Wed, 9 Feb 2000 19:01:12 +0100
Gerrit Holl wrote:
>> import random
>> listofn = range(1,1000) #a list containing integers from 1 to 999
>> a = random.choice(listofn) #choice a random element from a list
>> print a
>> I don't know if there's a better way for doing it but this works for me...
>It works, but the following has much better performance:
>>>> import random
>>>> random.randint(0, 1000)
>It doesn't need to create a list. Consider:
>>>> random.random() * 1000
>>>> round(random.random() * 1000)
>>>> int(round(random.random() * 1000))
Thanks for the note.
My problem is that I think:
1) make things work
2) make things work in a clever way
But I use to stop once I get the first step and go for another thing.