When should I use uuid.uuid1() vs. uuid.uuid4() in python?

后端 未结 6 1274
情话喂你
情话喂你 2020-12-07 07:43

I understand the differences between the two from the docs.

uuid1():
Generate a UUID from a host ID, sequence number, and the current time

<

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 08:19

    One instance when you may consider uuid1() rather than uuid4() is when UUIDs are produced on separate machines, for example when multiple online transactions are process on several machines for scaling purposes.

    In such a situation, the risks of having collisions due to poor choices in the way the pseudo-random number generators are initialized, for example, and also the potentially higher numbers of UUIDs produced render more likely the possibility of creating duplicate IDs.

    Another interest of uuid1(), in that case is that the machine where each GUID was initially produced is implicitly recorded (in the "node" part of UUID). This and the time info, may help if only with debugging.

提交回复
热议问题