[SciPy-user] random number

Gary Pajer gpajer at rider.edu
Tue Jun 29 12:05:25 CDT 2004


Steve Schmerler wrote:

>>You're right. Wasn't seed changing but truly out of bound call.
>>Why do you need to generate uniform variate (0,1e38) ?
>>Curious about applications !
>>
>>JC.
>>
>>    
>>
>
>I'm testing an evolution strategy (similar to a genetic algorithm) for
>parameter fitting. I need to construct parameter vectors
>
>    p = [p[1], ..., p[n]]
>
>where each p[i] sould be a random number from 0 to 1e200.
>
>I found that the module 'random' works with the 1e39-thing.
>
>    >>> from random import *
>    >>> uniform(0,1e39)
>    2.3437216521520377e+038
>    >>> uniform(0,1e200)
>    2.7167859425411156e+199 
>
>But there is another downside here. 
>
>    >>> x=[uniform(0,1e200) for i in range(1000)]
>
>gives nearly 1000 rn's like
>    
>    2.3107981948610023e+199
>
>All rn's have an order of magnitude of 1e199, but I want also things like
>e.g.
>
>    1e23, 1e45, 1e2, ....
>
>Any idea how to do this??? (google should do it :) )
>
>It seems as if 'uniform(min, max)' is implemented as
>
>   random()*max
>
>where 'random()' is a random float out of [0,1).  
>
>bye
>
>  
>
I was going to suggest random()*1e39,   but it seems that that is not 
really what you want.

A uniformly distributed collection of numbers between (0, 1e38) is going 
to have very few members between (0, 1e3).   Or  (0, 1e24).   Or (0, 
1e35).    Only 1 in 10 will be in the range (0, 1e37).    It sounds like 
you may be looking for logarithmically distributed numbers.

How about 10**x  where x is a random number in (0, 38).

Caveat:  I'm no expert in random numbers.  I'm just following my nose, here.

-gary   



More information about the SciPy-user mailing list