# secrets: Generate cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar. # secrets.SystemRandom: Alternate random number generator using sources provided by the operating system (such as /dev/urandom on Unix or CryptGenRandom on Windows). Not available on all systems (see os.urandom() for details). ! Considerações: Como pode-se notar, a biblioteca utiliza como pool de entropia as fontes fornecidas pelo sistema. - /dev/urandom :: Unix - CryptGenRandom :: MS-Windows """ # 🚨 Gerador randomico SEGURO generator = SystemRandom() print(generator.getrandbits(1024)) # Gera um inteiro de 1024-bits print(generator.random()) # 🕹 Gerador randomico USUAL do Python print(random.random()) """ ! Conclusão: Seguindo as documentações, ambos os geradores utilizam a mesma fonte de entropia. ? Podemos então afirmar que o PRNG built-in do Python é seguro? """
item = input("What are you giving away? ") n = int(input("How many {} are you giving away? ".format(item))) participants = int(input("How many people are participating? ")) print("To start, participants 0 through {} get one of the {} (for now...)".format(n - 1, item)) bus = list(range(n)) print() print("List anyone who was gone, end with a blank line...") s = n while True: line = input() if line == '': break print("Participant {} gets one of the {} (for now) then.".format(s, item)) bus[bus.index(int(line))] = s s += 1 j = n for e in range(s, participants): here = input("Is participant {} here (y/n)? ".format(e)) == 'y' if not here: continue j = j + 1 if rng.random() < n / j: i = rng.randrange(0, n) print("Participant {} steals one of the {} from participant {}!".format(e, item, bus[i])) bus[i] = e else: print("Nothing happened.")
matrix = [[0.] * len(idx_range) for _ in range(len(col_range))] for r in range(len(idx_range)): for c in range(len(col_range)): matrix[c][r] = round(idx_range[r] + col_range[c], 4) constant = 1 / sqrt(2 * pi) alpha = 0.05 conf_level = 1 - alpha n_trials = 1000 epochs = 100 results = [] for n in range(epochs): # rand_vals = [rnd.uniform(0, 1) for _ in range(n_trials)] rand_vals = [rnd.random() for _ in range(n_trials)] results.append( sum([1 if i <= conf_level else 0 for i in rand_vals]) / n_trials) mean(results) def cls_prop(name, datatype): """Class property helper function.""" mask_name = f"__{name}" @property def this_prop(self): return getattr(self, mask_name) @this_prop.setter