-4

I need to create a short unique ID which is a random sequence of numbers in python. So i need to allocate the short sequence to a user and also store it in a text file

Can some one please help me with this and give me an example??

4
  • 4
    read about uuid Commented Jul 9, 2016 at 13:18
  • Python has a random module that can be used to generate random numbers or integers in some specified range Commented Jul 9, 2016 at 13:21
  • @NendoTaka, IMO OP needs unique ID Commented Jul 9, 2016 at 13:22
  • It is impossible to have both a random and unique number unless you are removing that possibility from the random generation. Just add an if statement to check if it has been used and use a large range. Commented Jul 9, 2016 at 13:24

1 Answer 1

1

Use uuid:

import uuid
uuid.uuid4()

results in things like:

UUID('35ad767c-da61-4731-adbc-cdd96efac2c4')

And a link to the python docs: https://docs.python.org/3.5/library/uuid.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.