[Tutor] Random
JoanCarles p Casasín
joanca@typerware.com
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)
>67
>It doesn't need to create a list. Consider:
>>>> random.random() * 1000
>786.880856997
>>>> round(random.random() * 1000)
>30.0
>>>> int(round(random.random() * 1000))
>74
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.
Thanks!
JoanCarles
:::!!!:::
joanca@typerware.com
http://www.typerware.com