Binomial-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 Binomial. Sua tradução está 100% completa.
Outros idiomas:
English • ‎português do Brasil

It is the discrete probability distribution of a specific number of successes in a sequence of n independent experiments, each asking a yes-no question, and each with its own boolean-valued outcome: success with probability p or failure with probability [math]q = 1 - p[/math].

Sample Python Code

1 million attempts sample
def pseudo_binomial(n=100, p=0.5, size=1):
    """
    Binomial generator from uniform generator
    """
    binom = []
    for _ in range(size):
    
        # 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=n)
        Y = (U <= p).astype(int)
        binom.append(np.sum(Y))
    
    return binom