Snippets

Nathaniel Knight Consistent, isolated, random UUID generator

You are viewing an old version of this snippet. View the current version.
Revised by Nathaniel Knight 1b2d9e6
import random
import uuid


class RandomUuidGenerator:
    """Generates a sequence of pseudo-random UUIDs.
    
    Given the same seed, it will generate the same sequence.
    """

    def __init__(self, seed):
        self.rng = random.Random(seed)
    
    def gen_uuid(self):
        return uuid.UUID(bytes=[self.rng.getrandbits(8) for _ in range(16)], version=4)
    
        
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.