Guest User

Untitled

a guest
Dec 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. import random
  2. def birthday_attack(choices):
  3. tries = 0
  4. max_tries = choices**2
  5. chosen = set()
  6. choice = None
  7. while choice not in chosen and tries < max_tries:
  8. tries += 1
  9. if choice is not None:
  10. chosen.add(choice)
  11. choice = random.randrange(choices)
  12. return tries
  13. trials = 100000
  14. tries = [birthday_attack(2**8) for i in range(trials)]
  15. print(sum(tries)/trials)
  16. tries.sort()
  17. print(tries[trials//2])
Add Comment
Please, Sign In to add comment