You can use a UUID generator library or function that employs a reliable algorithm for generating UUIDs. You could also configure your database to use UUID as a primary key and set up a unique index on the UUID column to prevent duplicate UUIDs from being inserted.