Binomial-distributed Random Generator

De Augusto Baffa Wiki
Revisão de 09h48min de 30 de dezembro de 2020 por Abaffa (discussão | contribs) (Criou página com 'commoldura|direita|1 million attempts sample')
Ir para navegação Ir para pesquisar
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