Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.15 KB | None | 0 0
  1. w = [1,4,2,5] # Some data
  2. w_max = max(w)
  3. n = len(w)
  4.  
  5. while True:
  6. idx = random.randrange(n)
  7. u = w_max*random.random()
  8. if u <= w[idx]:
  9. break
  10. print idx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement