Skip to content

Commit

Permalink
increase guiderator default size from 12 to 24, range from 10-20 to 2…
Browse files Browse the repository at this point in the history
…0-36
  • Loading branch information
mahmoud committed Feb 28, 2017
1 parent d2603c5 commit 373276f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions boltons/iterutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,22 +963,23 @@ class GUIDerator(object):
Testing shows it to be around 12x faster than the uuid module. By
default it is also more compact, partly due to its default 96-bit
(12-byte) length. 96 bits of randomness means that there is a 1 in
2 ^ 32 chance of collision after 2 ^ 64 iterations. If more or
less uniqueness is desired, the *size* argument can be adjusted
(24-hexdigit) length. 96 bits of randomness means that there is a
1 in 2 ^ 32 chance of collision after 2 ^ 64 iterations. If more
or less uniqueness is desired, the *size* argument can be adjusted
accordingly.
Args:
size (int): character length of the GUID, defaults to 12. Lengths
between 10 and 20 are considered valid.
size (int): character length of the GUID, defaults to 24. Lengths
between 20 and 36 are considered valid.
The GUIDerator has built-in fork protection that causes it to
detect a fork on next iteration and reseed accordingly.
"""
def __init__(self, size=12):
def __init__(self, size=24):
self.size = size
if size < 10 or size > 20:
raise ValueError('expected 10 < size <= 20')
if size < 20 or size > 36:
raise ValueError('expected 20 < size <= 36')
self.count = itertools.count()
self.reseed()

Expand Down Expand Up @@ -1025,13 +1026,13 @@ class SequentialGUIDerator(GUIDerator):
The SequentialGUIDerator is aronud 50% faster than the normal
GUIDerator, making it almost 20x as fast as the built-in uuid
module. By default it is also more compact, partly due to its
96-bit (12-byte) default length. 96 bits of randomness means that
96-bit (24-hexdigit) default length. 96 bits of randomness means that
there is a 1 in 2 ^ 32 chance of collision after 2 ^ 64
iterations. If more or less uniqueness is desired, the *size*
argument can be adjusted accordingly.
Args:
size (int): character length of the GUID, defaults to 12.
size (int): character length of the GUID, defaults to 24.
Note that with SequentialGUIDerator there is a chance of GUIDs
growing larger than the size configured. The SequentialGUIDerator
Expand Down
8 changes: 4 additions & 4 deletions tests/test_iterutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ def test_guiderator():
assert guid != guid2

# custom size
guid_iter = GUIDerator(size=16)
assert len(next(guid_iter)) == 16
guid_iter = GUIDerator(size=26)
assert len(next(guid_iter)) == 26


def test_seqguiderator():
Expand All @@ -463,5 +463,5 @@ def test_seqguiderator():

# custom size
for x in range(10000):
guid_iter = GUIDerator(size=16)
assert len(next(guid_iter)) == 16
guid_iter = GUIDerator(size=26)
assert len(next(guid_iter)) == 26

0 comments on commit 373276f

Please sign in to comment.