Skip to content

Instantly share code, notes, and snippets.

@skyler
Created March 8, 2013 15:52
Show Gist options
  • Select an option

  • Save skyler/5117413 to your computer and use it in GitHub Desktop.

Select an option

Save skyler/5117413 to your computer and use it in GitHub Desktop.
"tickets.py" 20L, 502C written
from pprint import pprint
num_servers = 3
ids = []
gen_how_many = 10000
i = 0
while i < num_servers:
auto_inc_value = i + 1
new_ids = range(auto_inc_value, gen_how_many + 1, num_servers)
ids.extend(new_ids)
#print "generated ids"
#pprint(new_ids)
for id in new_ids:
if ids.count(id) > 1:
raise Exception("id %d is not unique" % id)
i = i + 1
print "generated %d unique ids across %d servers" % (len(ids), num_servers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment