A Sample Picker
Ir para navegação
Ir para pesquisar
Para sortear amostras a partir de um conjunto podemos utilizar o código abaixo.
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,