![]() |
generating random string unique forever - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: generating random string unique forever (/thread-34666.html) |
generating random string unique forever - Skaperen - Aug-19-2021 i want to run many processes in parallel that can generate a random-like string that is absolutely unique forever. well, forever is a long time. the string needs to be unique over the course of a long time, across as many processes a host can run in that time. maybe this time should be a year. the processes, no matter how long they are delayed, must have an absolutely unique string suitable for naming a resource in a common name space such as a file system. there must never be a collision. what callable function or method could do this? this must work without creating an additional process in any way (no invoking a command). it must be portable across major platforms. RE: generating random string unique forever - bowlofred - Aug-19-2021 https://en.wikipedia.org/wiki/Universally_unique_identifier >>> import uuid >>> uuid.uuid1() UUID('7bd82050-0084-11ec-9454-acde48001122')If you might run two at once on the same machine, then just go random. >>> uuid.uuid4() UUID('b49c5e72-205a-4495-811f-d33b134db2a2') RE: generating random string unique forever - BashBedlam - Aug-19-2021 How about using the current time? import time random_sting = str (time.time ()).replace ('.', '') print (random_sting) RE: generating random string unique forever - Skaperen - Aug-19-2021 is time.time() unique across multiple processes calling it at the same instant? i suppose i could tuple it with the process ID. RE: generating random string unique forever - bowlofred - Aug-19-2021 (Aug-19-2021, 01:33 AM)Skaperen Wrote: is time.time() unique across multiple processes calling it at the same instant? i suppose i could tuple it with the process ID. My experience is no. If you might be running multiple on one host, just use uuid4(). RE: generating random string unique forever - Gribouillis - Aug-20-2021 You already posted a similar thread about one year ago! The answer is still the same. |