0

I need to create a set of static UUIDs in python which is each time the same.

So I created the following function:

def uuid_generator():
    seed = 2459234408052414943112311245669091401656 # Just a large random number
    while True:
        yield uuid.UUID(int=seed)
        seed += 1

This function works fine so far, but I don't like the fact that the UUIDs are just upcounting by this implementation.

So I'm wondering how to change the UUID seed value each time the function is called, so the generated UUIDs

  • Remain deterministic
  • Are each time different (for a relatively small number of calls, let's say 1000 UUIDs)
  • Changed in a way they are not just counting up by one.
2
  • 2
    Create an array of seeds, randomly generated using a single seed, then iterate over that array in your while True loop Commented Apr 15, 2020 at 13:32
  • @nicomp Thank you for the hint. I forgot that random also behaves deterministic (based on the seed value). I posted an answer using random with a constant seed to generate the UUIDs. Commented Apr 15, 2020 at 14:18

1 Answer 1

3

Thanks to the comment to the original question I found the following solution for the problem:

def uuid_generator():
    random.seed(633458965612378623578) # Some random number

    while True:
        yield uuid.UUID(int=random.getrandbits(128))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.