Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Nov 2013
    Posts
    146
    Member #
    37737
    Liked
    15 times

    Random, Unique, 6 Digit, Number

    I need to find a way to make a truly unique random 6 digit number using php/mysql. It's for ticket numbers for a help desk system.

    Lots of different ways but they all have something wrong with them, like they are too slow, or they are not truly random. mysql - How generate UNIQUE random number in php - Stack Overflow

    Right now I'm just using
    PHP Code:
    $tid = echo rand(000000999999); 
    but this could be ununique and its not always 6 digits

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,139
    Member #
    27197
    Liked
    959 times
    In order to make it unique you'll need to store the previously used numbers in a database table and check the generated numbers against all of the previously used ones. If you want it to always be 6 digits, you'll want to set the lower limit to 100000.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Senior Member
    Join Date
    Nov 2013
    Posts
    146
    Member #
    37737
    Liked
    15 times
    Quote Originally Posted by Ronald Roe View Post
    In order to make it unique you'll need to store the previously used numbers in a database table and check the generated numbers against all of the previously used ones. If you want it to always be 6 digits, you'll want to set the lower limit to 100000.
    Wow, duh, I can't believe I didn't realize I had to put a 1 at the front! Thank you!
    Could you please assist me in the code for the other portion?
    Last edited by noodles415; Aug 31st, 2014 at 06:12 PM.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:10 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com