[Python-Dev] UUID module (original) (raw)

Ka-Ping Yee python-dev at zesty.ca
Sat Jun 10 15:27:08 CEST 2006


On Sat, 10 Jun 2006, Mike Brown wrote:

I have a couple of suggestions for improving that implementation:

1. You're currently using os.urandom, which can raise a NotImplementedError. You should be prepared to fall back on a different PRNG...

The latest version (http://zesty.ca/python/uuid.py) does this.

2. random.randrange is a method on a default random.Random instance that, although seeded by urandom (if available), may not be the user's preferred PRNG. I recommend making it possible for the user to supply their own random.Random instance for use by the module.

I decided not to add more code to do this, because the UUID constructor is now designed in such a way that it's very simple to convert your own randomness into a UUID. If you want to use another source of randomness, you'd just get 16 random bytes and then call UUID(bytes=random_stuff, version=4).

That seems simpler to me than adding an extra argument and requiring a randrange() method on it.

-- ?!ng



More information about the Python-Dev mailing list