Translations:Gerador Aleatório para Distribuição Normal/4/en

De Augusto Baffa Wiki
Ir para navegação Ir para pesquisar
def pseudo_normal(mu=0.0, sigma=1.0, size=1):
    """
    Generates normal distribution from uniform generator
       using Box-Muller transform
    """
    # Sets seed based on the decimal portion of the current system clock
    t = time.perf_counter()
    seed1 = int(10**9*float(str(t-int(t))[0:]))
    U1 = pseudo_uniform(seed=seed1, size=size)
    
    t = time.perf_counter()
    seed2 = int(10**9*float(str(t-int(t))[0:]))
    U2 = pseudo_uniform(seed=seed2, size=size)
    
    # Standard Normal pair
    Z0 = np.sqrt(-2*np.log(U1)) * np.cos(2*np.pi*U2)
    Z1 = np.sqrt(-2*np.log(U1)) * np.sin(2*np.pi*U2)    
    
    # Scaling
    Z0 = Z0 * sigma + mu
    
    return Z0