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

    3
    ReputationRep:
    Hey!

    How do you generate a set 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 from a set of random numbers and so yeah they will be basically given a case number which will then be sent off to a technician.

    How would I code this on python?

    Thanks!
    Offline

    10
    ReputationRep:
    Check 'import random'.

    This module has random.random, random.randrange, random.uniform, random.randint.

    The number generated can be assigned just like any other value to a variable.
    Offline

    18
    ReputationRep:
    How are you doing it?

    If its just a random number you want to generate you could try random.randint(x,y) (after importing random of course).
    put it in a loop which runs till all users have a number.

    Are you adding the random number to an already existing database? or are you taking in the users question and then adding the users random number and question into a database?
    Offline

    18
    ReputationRep:
    the random module will help, as others have said.
    Offline

    15
    ReputationRep:
    Not at my PC so I can't write anything for you. I also don't know Python and have no experience with database programming, so take this with a pinch of salt.

    Firstly: in your database, define a new variable which may be later assigned. This doesn't have to be a continuous database -- just the one which is created when a new user makes a ticket.
    When a new user is created, allocate new variable a number using the randrange(a, b) function.
    Use an if() equality statement to re-assign them a new code if it clashes with another user's.
    • Thread Starter
    Offline

    3
    ReputationRep:
    ah, okay, i sort of understand.




    (Original post by kelefi)
    How are you doing it?

    If its just a random number you want to generate you could try random.randint(x,y) (after importing random of course).
    put it in a loop which runs till all users have a number.

    Are you adding the random number to an already existing database? or are you taking in the users question and then adding the users random number and question into a database?
    And this is what i need to do:If no solution to the user's query is found, the data (which is specific info about their computer and the problem they are having) is allocated a case number and stored to be sent to a technician.After importing random, or using randint, what do I do. Like i need to allocate a different number to the user each time the python program is run so that no two users get the same case number.

    Would anyone be able to give an example please?
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Would you like to hibernate through the winter months?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • 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

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