Exponential-distributed Random Generator

De Augusto Baffa Wiki
Ir para navegação Ir para pesquisar
Esta página é uma versão traduzida da página Gerador Aleatório para Distribuição Exponencial. Sua tradução está 100% completa.
Outros idiomas:
English • ‎português do Brasil

It is the continuous probability distribution of the time between events in a Poisson point process, i.e., a process in which events occur continuously and independently at a constant average rate.

For generating an Exponential distribution from a Uniform distribution, we can use a powerful technique called “Inverse Transform Method”. We don’t need to dwell on the theoretical details here, but ultimately this method links the two types of distributions through a simple mathematical transformation.

[math]Exp(i; \lambda) = -\frac{1}{\lambda}.ln(1 - U_i)[/math]

Sample Python Code

1 million attempts sample
def pseudo_exp(lamb, size=1):
    """
    Generates exponential distribution from uniform generator
    """
    # Sets seed based on the decimal portion of the current system clock
    t = time.perf_counter()
    seed = int(10**9*float(str(t-int(t))[0:]))
    
    U = pseudo_uniform(seed=seed, size=size)
    X = -(1/lamb)*(np.log(1-U))
    
    return X