# pydicom.uid.generate_uid

pydicom.uid.generate_uid(prefix: str | None = '1.2.826.0.1.3680043.8.498.', entropy_srcs: list[str] | None = None) → UID

  Return a 64 character UID which starts with prefix.

  Changed in version 3.0:

  - When entropy_srcs is `None` the suffix is now generated using `randbelow()`

  - The maximum length of prefix is now 54 characters

  Parameters:

    - prefix (str or None, optional) – The UID prefix to use when creating the UID. Default is the pydicom root UID `'1.2.826.0.1.3680043.8.498.'`. If prefix is `None` then a prefix of `'2.25.'` will be used with the integer form of a UUID generated using the `uuid.uuid4()` algorithm.

    - entropy_srcs (list of str, optional) – If prefix is used then the prefix will be appended with a SHA512 hash of the supplied `list` which means the result is deterministic and should make the original data unrecoverable. If entropy_srcs isn’t used then a random number from `secrets.randbelow()` will be appended to the prefix. If prefix is `None` then entropy_srcs has no effect.

  Returns:

    A DICOM UID of up to 64 characters.

  Return type:

    pydicom.uid.UID

  Raises:

    ValueError – If prefix is invalid or greater than 54 characters.

  Examples

      >>> from pydicom.uid import generate_uid
      >>> generate_uid()
      1.2.826.0.1.3680043.8.498.22463838056059845879389038257786771680
      >>> generate_uid(prefix=None)
      2.25.167161297070865690102504091919570542144
      >>> generate_uid(entropy_srcs=['lorem', 'ipsum'])
      1.2.826.0.1.3680043.8.498.87507166259346337659265156363895084463
      >>> generate_uid(entropy_srcs=['lorem', 'ipsum'])
      1.2.826.0.1.3680043.8.498.87507166259346337659265156363895084463

  References

  - DICOM Standard, Part 5, Chapters 9 and Annex B

  - ISO/IEC 9834-8/ITU-T X.667