Bernoulli-distributed Random Generator

De Augusto Baffa Wiki
Revisão de 17h57min de 28 de dezembro de 2020 por Abaffa (discussão | contribs) (Criou página com 'This is a discrete probability distribution that can be thought of as a model for the set of possible outcomes of any single experiment that asks a yes-no question (or true-fa...')
Ir para navegação Ir para pesquisar
Outros idiomas:
English • ‎português do Brasil

This is a discrete probability distribution that can be thought of as a model for the set of possible outcomes of any single experiment that asks a yes-no question (or true-false). The single parameter is denoted p (probability of success).

Exemplo em Python

Exemplo com 1 milhão de sorteios
def pseudo_bernoulli(p=0.5, size=1):
    """
    Bernoulli generator 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)
    B = (U <= p).astype(int)
    
    return B