Using the Random Module.

Dan Stromberg dstromberglists at gmail.com
Sat Jul 12 07:04:54 CEST 2008


On Fri, 11 Jul 2008 12:27:32 -0700, castironpi wrote:

> On Jul 11, 1:29 pm, WDC <ki4... at gmail.com> wrote:
>> On Jul 11, 2:15 pm, Michiel Overtoom <mot... at xs4all.nl> wrote:
>>
>> > You wrote...
>> > >Is there a better way to do that besides doing this:
>>
>> > >>>>random.randint(00000000000000000, 99999999999999999)
>> > >09657398671238769
>>
>> > Maybe this?
>>
>> >         random.randint(0, 9e16)
>>
>> > --
>> > "The ability of the OSS process to collect and harness the collective
>> > IQ of thousands of individuals across the Internet is simply
>> > amazing." - Vinod
>> > Vallopillilhttp://www.catb.org/~esr/halloween/halloween4.html
>>
>> That would work yes, but is there a random() function that would do
>> that without the attributes? Not trying to be lazy, I just want to know
>> if there is a built in way.
>>
>> Thanks Michiel.
> 
> You want a random integer.  Is there a range you want it in?
> 
> Past a certain point, you'll exceed the granularity of the random number
> generator, and some values in the range will never be generated.

In which case you might grab random numbers, and'ing them with 0xffff or 
0xffffffff or something at a time, and then smoosh them together with 
shifts and or's, or multiplication and addition, to get the precision you 
need.




More information about the Python-list mailing list