vendredi 13 décembre 2019

Generate random 6-digit ID in Python

I have a database of questions. I want to mark them with 6-digit ID.

I have tried using uuid.uuid1() with int() but it generates a 128-bit integer and that is too long.

I have also tried using random() but that random integer cannot have digit '0' as first digit.

The ID:

  • Can start with digit '0'.
  • There is a space between the first 3 digits and the last 3 digits.
  • Must be unique (random ID).

For example, question 1 can be marked 050 124 How can I create random ID like that?




Aucun commentaire:

Enregistrer un commentaire