Skip to content

Commit

Permalink
Update balls_bins.py
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
  • Loading branch information
romange authored Oct 10, 2023
1 parent 5ddc0ca commit 584ce2c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tools/balls_bins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import matplotlib.pyplot as plt


def simulate_balls_into_bins(balls: int, N, threshold: int, exact, trials=10000):
def simulate_balls_into_bins(balls: int, bins: int, threshold: int, exact, trials=10000):
"""Simulate throwing M balls into N bins for a given number of trials."""
counts = np.zeros(N, dtype=int)
counts = np.zeros(bins, dtype=int)
success = 0
exact_success = 0
deltas = []
Expand All @@ -19,8 +19,8 @@ def simulate_balls_into_bins(balls: int, N, threshold: int, exact, trials=10000)
counts.fill(0)

# Throw M balls into the bins
bins = np.random.randint(0, N, balls)
unique, counts_bins = np.unique(bins, return_counts=True)
bins_seq = np.random.randint(0, bins, balls)
unique, counts_bins = np.unique(bins_seq, return_counts=True)
counts[unique] += counts_bins
deltas.append(counts.max() - counts.min())
# Check if any bin has K or more balls
Expand Down

0 comments on commit 584ce2c

Please sign in to comment.