#1
  1. No Profile Picture
    Give peace a chance.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    Buenos Aires, Argentina
    Posts
    83
    Rep Power
    14

    random ID numbers


    I'm making a system and I've found a problem that I didn't realize I had.
    There's a tool in this system too add new users, blank users that will be filled later, this users are records in a mysql database and the ID of this users have to be random. Any idea of how can I make it ?
    I mean, I have to alocate N (N provided by the user) random ID numbers which are inside a range K:L (K and L provided by the user) which are not in the database yet.
    I think there wouldn't be any problem since they're specting about 2000 users and the comon range is from 1000 to 9999 (and the database supports more a really great range).
    any tip ? any hint ?
    Thank you.
    PS: this will be done in PHP with MySQL
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    29
    One quick solution would be to have a table that holds all the ID numbers and a flag to show whether that ID has been used yet. If the user said he needed 2000 ID numbers between 1000 and 9999, you would populate the table with 2000 random numbers within that range. Each time an ID number was needed, you would select a number from the ID table whose "in use" flag hadn't been set yet and then set that "in use" flag to true for that ID number. You could also select the numbers from the table in a random order so that the random numbers in the table would not be used in sequential order. This would also lessen the chance of two users picking the same ID number from the table at the same time.

IMN logo majestic logo threadwatch logo seochat tools logo