Skip to content

Instantly share code, notes, and snippets.

@shuax
Created December 7, 2017 03:24
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 shuax/1907e157dacb765c737d6e72eccb93bc to your computer and use it in GitHub Desktop.
Save shuax/1907e157dacb765c737d6e72eccb93bc to your computer and use it in GitHub Desktop.
import random
def shuffle_assign(total, num):
remain = total - num
assert remain >= 0
points = []
for i in range(1, num):
point = random.randint(0, remain)
points.append(point)
points.append(remain)
points.sort()
for i in reversed(range(1, num)):
points[i] = points[i] - points[i - 1]
return [x + 1 for x in points]
from collections import Counter
c = Counter()
for x in range(10000):
parts = shuffle_assign(60, 5)
for i, v in enumerate(parts, 1):
c[i] += v
print(c)
print(shuffle_assign(20, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment