Skip to content

Instantly share code, notes, and snippets.

@emtwo
Created January 28, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emtwo/95b420b21041db47efb5b331011e43b6 to your computer and use it in GitHub Desktop.
Save emtwo/95b420b21041db47efb5b331011e43b6 to your computer and use it in GitHub Desktop.
import math
def exponential_range(min, max, bucket_count):
log_max = math.log(max);
ranges = []
current = min;
if current == 0:
current = 1
# undeflow bucket
ranges.append(0)
ranges.append(current)
for i in range(2, bucket_count):
log_current = math.log(current)
log_ratio = (log_max - log_current) / (bucket_count - i)
log_next = log_current + log_ratio
next_value = round(math.exp(log_next))
current = next_value if next_value > current else current + 1
ranges.append(current)
return ranges
def exponential_bucketing():
print(exponential_range(0, 10000, 50))
exponential_bucketing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment