Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- from decimal import *
- # translates x from [a:b] to [alpha:beta]
- def translate(x, a, b, alpha, beta):
- y = alpha + ((beta - alpha) * ((x - a)/ (b - a)))
- return y
- #--------------------------------------------------------------
- # Things that should be defined elsewhere
- #
- tipped = 100 # tipped amount
- active = 9 # active users (including the user who tips the soaker)
- tip_min = 10 # minimum tip there will be
- #--------------------------------------------------------------
- # Settings for the random soak
- #
- ceil = 1 # 100%
- # floor is defined depending on the tip and will get closer to 100% when the tip gets big
- floor = min(translate(Decimal.ln(Decimal(tipped)), Decimal.ln(Decimal(tip_min)), 14, 50, 100), 100)/100
- print("ceil: %i%% | floor: %i%% | active: %s | tip: %s" % (ceil*100, floor*100, active, tipped))
- mean = int(tipped / (active - 1)) # the normal tipping amount (same share among all users)
- tip_ceil = int(mean*ceil) # 100%
- tip_floor = max(int(mean*floor), tip_min) # floor%
- tips = [] # will be a random array of tip amounts
- #--------------------------------------------------------------
- # The random soak algorithm
- #
- # initializing
- remaining = tipped
- # getting the random tip
- for i in range(active - 1):
- _max = min(remaining, tip_ceil)
- _min = min(tip_floor, remaining)
- user_i_tip = int(random.uniform(_min, _max))
- tips.append(user_i_tip)
- remaining = remaining - user_i_tip
- # sharing the remaining coins
- while remaining > tip_min:
- i = int(random.uniform(0, active - 1))
- _tip = int(random.uniform(0, remaining))
- remaining = remaining - _tip
- tips[i] = tips[i] + _tip
- # tips is now an array of length (active-1) filled with random tip amounts
- print(tips)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement