version4.rst 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. .. _rfc4122.version4:
  2. =================
  3. Version 4: Random
  4. =================
  5. Version 4 UUIDs are perhaps the most popular form of UUID. They are
  6. randomly-generated and do not contain any information about the time they are
  7. created or the machine that generated them. If you don't care about this
  8. information, then a version 4 UUID might be perfect for your needs.
  9. .. code-block:: php
  10. :caption: Generate a version 4, random UUID
  11. :name: rfc4122.version4.example
  12. use Ramsey\Uuid\Uuid;
  13. $uuid = Uuid::uuid4();
  14. printf(
  15. "UUID: %s\nVersion: %d\n",
  16. $uuid->toString(),
  17. $uuid->getFields()->getVersion()
  18. );
  19. This will generate a version 4 UUID and print out its string representation.
  20. It will look something like this:
  21. .. code-block:: text
  22. UUID: 1ee9aa1b-6510-4105-92b9-7171bb2f3089
  23. Version: 4
  24. .. tip::
  25. Version 4 UUIDs generated in ramsey/uuid are instances of UuidV4. Check out
  26. the :php:class:`Ramsey\\Uuid\\Rfc4122\\UuidV4` API documentation to learn
  27. more about what you can do with a UuidV4 instance.