-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Faker::Internet.uuid #1603
Add Faker::Internet.uuid #1603
Conversation
lib/faker/default/internet.rb
Outdated
@@ -192,6 +192,10 @@ def user_agent(vendor = nil) | |||
sample(agents) | |||
end | |||
|
|||
def uuid | |||
Faker::Config.random.bytes(16).unpack('H8H4H4H4H12').join('-') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably best to generate a valid version4 UUID incase there's a library out there that does something special based on the version. For Faker's purposes, that just means that we need to make sure the first digit in the 3rd block is always a 4:
xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
🎊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed 👍
* Add Faker::Internet.uuid * Make uuid v4 compatible
* Add Faker::Internet.uuid * Make uuid v4 compatible
UUIDs are incredibly common. Many databases, APIs, etc will use them to identify resources. Being able to generate these easily is paramount to having a productive development environment.
So, why not just use
SecureRandom.uuid
?The beauty of faker is that is can be used to generate deterministic sequences of numbers in a non-deterministic world. This makes debugging much easier, as we have one less thing to reason about.
This patch uses fakers PRNG to build a UUID, which solves this problem.
supersedes #943