question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not possible to seed uuid4

See original GitHub issue

It is not possible to seed the uuid4 property.

>>> f1 = Faker()
>>> f1.seed(4321)
>>> print(f1.uuid4())
4a6d35db-b61b-49ed-a225-e16bc164f7cc

>>> f2 = Faker()
>>> f2.seed(4321)
>>> print(f2.uuid4())
b5f05be8-2f57-4a52-9b6f-5bcd03125278

The solution is pretty much given in: http://stackoverflow.com/questions/41186818/how-to-generate-a-random-uuid-which-is-reproducible-with-a-seed-in-python

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kevin-browncommented, Nov 30, 2020

The tests which were added in #1050 (and closed out this ticket) are still in the repo at

https://github.com/joke2k/faker/blob/594d34414b137071f59b9fc75442206244c234cd/tests/providers/test_misc.py#L68-L75

I don’t use Faker anymore, but after looking at the code it looks like it should now work with seeding and properly return v4 UUIDs.

1reaction
kevin-browncommented, Mar 20, 2017

Is it correct that you can’t see a difference between an (incorrect) UUID4 in Faker and a valid UUID4?

That is not correct. And 15/16 times it will produce a UUID that is not version 4.

>>> u = uuid.UUID(int=random.getrandbits(128))
>>> u
UUID('7119ccd3-e9be-c160-8d0d-608e5f5ea285')
>>> u.version
12

There are a total of 8 bits that must be set manually in order for it to be properly detected as a UUIDv4.

>>> uuid.UUID(int=(random.getrandbits(128) | (1<<63) | (1<<78)) & (~(1<<79) & ~(1<<77) & ~(1<<76) & ~(1<<62))).version
4
>>> uuid.UUID(int=(random.getrandbits(128) | (1<<63) | (1<<78)) & (~(1<<79) & ~(1<<77) & ~(1<<76) & ~(1<<62))).version
4
>>> uuid.UUID(int=(random.getrandbits(128) | (1<<63) | (1<<78)) & (~(1<<79) & ~(1<<77) & ~(1<<76) & ~(1<<62))).version
4
>>> uuid.UUID(int=(random.getrandbits(128) | (1<<63) | (1<<78)) & (~(1<<79) & ~(1<<77) & ~(1<<76) & ~(1<<62))).version
4
>>> uuid.UUID(int=(random.getrandbits(128) | (1<<63) | (1<<78)) & (~(1<<79) & ~(1<<77) & ~(1<<76) & ~(1<<62))).version
4
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to generate a random UUID which is reproducible (with a ...
I would like to be able to generate the same random UUID every time I run a script - that is, I'd like...
Read more >
Consistent Random UUIDs in Python - Nathaniel Knight
This is a little trickier than I thought it would be, but it's certainly possible. My first instinct was to set the random...
Read more >
uuid — UUID objects according to RFC 4122 ... - Python Docs
uuid4 () creates a random UUID. Depending on support from the underlying platform, uuid1() may or may not return a “safe” UUID. A...
Read more >
A Complete Guide to UUID Versions (v1, v4, v5) - With Examples
UUIDs address the problem of generating a unique ID - either randomly, or using some data as a seed. However, ensuring uniqueness is...
Read more >
Python UUID Module to Generate Universally Unique Identifiers
Generate a reproducible UUID using a seed value; Extract UUID attributes ... Also, read Working with random data in Python (Complete Guide).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found