[SciPy-user] random number

Steve Schmerler elcorto at gmx.net
Tue Jun 29 16:53:57 EDT 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.

Yes. The problem is that the minimal random numbers are mostly only 1e1
smaller (1e199) than the max value (1e200 in my case).

> 
> 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).
> 

Yeah, I tried something similar:

    import random
    from Numeric import *
    def alloverRand(min, max):
        # e.g. max = x*10**y = exp(max_exponent)
        max_exponent = log(max)
        return exp(random.uniform(.1*max_exponent,max_exponent))        

This gives log-like distribution. Though it's not uniformly I'll test if it
works since it covers _all_ numbers from (nearly 0) to 'max'.

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

me neither, so do I :)
thanx!

bye


-- 
All those who believe in psychokinesis raise
my hand. - Steven Wright
--

"Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
Jetzt aktivieren unter http://www.gmx.net/info




More information about the SciPy-User mailing list