George Sp
George Sp

Reputation: 572

Unique identification value in python3

I want to generate a unique value, or uuid, (I do not care if it is a number or hex) for some script produced documents in a python3 script, but this should be unique between multiple executions of the script.

etc. The script might run every two (2) or three (3) days. I do not want to get the same uuid twice.

A simple yet practical way I thought of is using the epoch time (since the script won't run twice at the same second) and the machine it will be running will be 64bit (2038 problem), but it seems to simple to be foolproof.

Another way to achieve this would be to use uuid4(). Will this be unique between executions and different machines?

Upvotes: 3

Views: 119

Answers (2)

Deepak Saini
Deepak Saini

Reputation: 2910

As @Chris Conlan mentions, uuid4() would be unique with almost certain probability. But, you can also name the files with the UNIX timestamp, i.e, the output of time.time().

Upvotes: 2

Chris Conlan
Chris Conlan

Reputation: 2962

uuid4() is cryptographically guaranteed to be unique. In practice, you can go so far as to assume that every UUID ever generated is unique.

I refer you to this: How unique is UUID?

Upvotes: 3

Related Questions