Created
March 8, 2013 15:52
-
-
Save skyler/5117413 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "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