A Sample Picker

De Augusto Baffa Wiki
Revisão de 17h43min de 28 de dezembro de 2020 por Abaffa (discussão | contribs) (Criou página com 'We can use the sample code below to draw samples from a set.')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)
Ir para navegação Ir para pesquisar
Outros idiomas:
English • ‎português do Brasil

We can use the sample code below to draw samples from a set.

Sample Python Code

def sample_picker(lst):
    """
    Picks up a random sample from a given list
    """
    # 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:]))
    
    # Random sample as an index
    s = pseudo_uniform(low=0,high=len(lst),seed=seed,size=1)
    idx = int(s)
    
    return (lst[idx])

Example:

dice_faces = ['one', 'two', 'three', 'four', 'five', 'six']

for _ in range(30):
    print(sample_picker(dice_faces), end=', ')

five, five, one, two, four, six, one, three, four, six, one, two, four, five, one, two, three, five, six, one, three, four, six, one, three, four, six, one, two, four,