Python Forum
generating random string unique forever
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
generating random string unique forever
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
https://en.wikipedia.org/wiki/Universall...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')
ndc85430 likes this post
Reply
#3
How about using the current time?

import time

random_sting = str (time.time ()).replace ('.', '')
print (random_sting)
Reply
#4
is time.time() unique across multiple processes calling it at the same instant? i suppose i could tuple it with the process ID.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
(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().
Reply
#6
You already posted a similar thread about one year ago! The answer is still the same.
buran and Yoriz like this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sample random, unique string pairs from a list without repetitions walterwhite 1 465 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  Generating random business cards Inkanus 2 2,213 Dec-08-2020, 09:41 PM
Last Post: buran
  Increase Numbers forever and need reset? ATARI_LIVE 4 2,358 Oct-23-2020, 01:55 PM
Last Post: ATARI_LIVE
  python multiprocessing import Pool, cpu_count: causes forever loop | help to remove Hassibayub 0 1,877 Jun-18-2020, 05:27 PM
Last Post: Hassibayub
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,432 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Generate String Only Unique to That Platform firesh 2 2,125 Sep-10-2019, 09:36 PM
Last Post: firesh
  Unique Random ID on Table talius 2 2,172 May-30-2019, 01:47 PM
Last Post: michalmonday
  Generate unique random numbers from different lists Takeshio 5 3,798 May-24-2019, 07:29 PM
Last Post: ichabod801
  Replace a list or string element with a random one.. pianistseb 3 2,444 May-09-2019, 08:24 AM
Last Post: buran
  problems with random number/string PrasadPython 3 2,602 Mar-01-2019, 06:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020