Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    10
    ReputationRep:
    How do you generate a short sequence of random numbers and allocate it to the user on python. Like say if they input the question 'How do i fix my computer?' , they should be given a unique id and they will basically be given a case number which will then be sent off to a technician.



    How would I code this with python??

    Would anyone be able to give an example please?????

    Thanks
    • Thread Starter
    Offline

    10
    ReputationRep:
    bump
    Offline

    3
    ReputationRep:
    If you want a case number that is (somewhat) easy to remember or communicate verbally then you should look at the random module, however depending on how large a number you generate and how long you will be generating numbers for it would be possible to eventually get a conflict of duplicate numbers (so you would have to keep track of previous numbers and if you get one again regenerate), if you don't care about readability and don't want to keep track of previous id's then using the uuid module would be better and drastically lower the probability of getting a duplicate id.
    Code:
    >>> import uuid
    >>> str(uuid.uuid4())
    'c5227b41-8331-46be-935f-5acdb9662b57'
    >>> str(uuid.uuid4())
    '213b0409-c051-4f04-a3ac-af8be4d7977e'
    >>> str(uuid.uuid4())
    'a1fbeb4f-f901-425d-a15a-5f65c64e7b0a'
    >>> str(uuid.uuid4())
    '7e23039e-7035-4afc-adf1-7a995da7bdf7'
    >>> str(uuid.uuid4())
    '744ba11e-d379-4368-84bb-c8ab2eebdb8b'
    >>> str(uuid.uuid4())
    'b5e888d9-2fe4-4172-bcc6-e2a1d656161a'
    >>> str(uuid.uuid4())
    'a410e726-3b5b-48a1-a44a-df38f6cafdef'
    >>> str(uuid.uuid4())
    '175d5669-3480-4c67-8113-95cd2f9ff393'
    >>> str(uuid.uuid4())
    '078b9e59-74e6-402b-b7f1-5b2ace959bfd'
    >>> str(uuid.uuid4())
    'ab43b628-65be-4c51-b6c0-afc7141d84c8'
    Offline

    15
    ReputationRep:
    (Original post by bluepearl7)
    How do you generate a short sequence of random numbers and allocate it to the user on python. Like say if they input the question 'How do i fix my computer?' , they should be given a unique id and they will basically be given a case number which will then be sent off to a technician.



    How would I code this with python??

    Would anyone be able to give an example please?????

    Thanks
    With the use of variables and random.randint.
    Assign the list of random numbers to a new variable.

    http://stackoverflow.com/questions/2...within-a-range
    Offline

    3
    ReputationRep:
    Code:
    from random import randint #imports relevant libraries
    
    caseNumber = (randint(1,100)) * 12345#defines caseNumber to equal a random number, multiplies that number by 12345 so it is a long number
    print (caseNumber)
    That will work, but it's definitely not the best way to do it
    Offline

    2
    ReputationRep:
    Very nice and simple way to get a 5 figure number everytime
    Code:
    from random import randint
    
    total = ''
    for i in range (5):
        x = randint(1,9)
        total = total + ''.join(str(x))
    print (total)
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.