Skip to content
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 generation of uuid V4 #325

Closed
ktom opened this issue May 19, 2021 · 5 comments
Closed

Add generation of uuid V4 #325

ktom opened this issue May 19, 2021 · 5 comments

Comments

@ktom
Copy link

ktom commented May 19, 2021

Hello,

In Faker there is support for uuids but only version 3. Would you consider adding support for V4 as well ?

There was a PR in the old repo fzaninotto#1536

https://github.com/symfony/polyfill-uuid/blob/main/Uuid.php could be relevant here and could also be used to generate the other versions

I can make a PR if you're up for the change

@pimjansen
Copy link

Well im open for it but adding another lib to implement all this crypto stuff is a bit overkill imo.

For 2.0 we improve the way we use extensions so i guess the best way there would be to create an extension that has a dependency on the ramsey uuid lib. We do not want this from core point of view but duplicating stuff again is also not right.

@ktom
Copy link
Author

ktom commented May 19, 2021

Thank you for the feedback
ramsey uuid seems the way to go indeed.

I've also found some quite simple scripts here and there, like in the PHP doc but i don't know how reliable they are and if the mt_rand usage would fit with faker

public static function v4() {
    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',

      // 32 bits for "time_low"
      mt_rand(0, 0xffff), mt_rand(0, 0xffff),

      // 16 bits for "time_mid"
      mt_rand(0, 0xffff),

      // 16 bits for "time_hi_and_version",
      // four most significant bits holds version number 4
      mt_rand(0, 0x0fff) | 0x4000,

      // 16 bits, 8 bits for "clk_seq_hi_res",
      // 8 bits for "clk_seq_low",
      // two most significant bits holds zero and one for variant DCE1.1
      mt_rand(0, 0x3fff) | 0x8000,

      // 48 bits for "node"
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
    );
  }

I can also easily build a small provider for my app for the moment

@pimjansen
Copy link

Indeed. Lets stick with this approach since if you look at the total installs and stars and such this is the way to go. Its a simple lib and atleast we know that they are valid at that point (crypto stuff)

I will note it down for a possible extension for v2 though!

@ktom
Copy link
Author

ktom commented May 20, 2021

Lets stick with this approach

Sorry i'm not sure i got your point here: did you mean add a simple function in v1 or build my own ?

@pimjansen
Copy link

Add your own for now.

@ktom ktom closed this as completed May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants