Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. from random import random
  2. from math import sqrt
  3. NUM_TARGETS = 2
  4. divis = sqrt(NUM_TARGETS)
  5. shards = 0
  6. last_shard = 0
  7. accum = 0.0
  8. l = []
  9. NUM_SHARDS = 100000
  10. overflow = 0
  11. ticks = 0
  12. while shards < NUM_SHARDS:
  13. for target in xrange(NUM_TARGETS):
  14. ticks += 1
  15. inc = random() * 0.32
  16. assert(0 <= inc <= 0.32)
  17. if target == 0:
  18. inc *= 1.15
  19. accum += inc
  20. if accum >= divis:
  21. overflow += (accum - divis)
  22. accum -= 1
  23. shards += 1
  24. l.append(last_shard + 1)
  25. last_shard = 0
  26. else:
  27. last_shard += 1
  28.  
  29. print sum(l), ticks
  30. print (overflow / NUM_SHARDS)
  31. from collections import Counter
  32. c = Counter(l)
  33. for k in sorted(list(c.keys())):
  34. print k, float(c[k]) / NUM_SHARDS * 100
  35. print (float(sum(l)) / NUM_SHARDS)
  36. print (NUM_SHARDS / (float(sum(l))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement