Results 1 to 5 of 5

Thread: Generating a random 10 digit number

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    62

    Generating a random 10 digit number

    Mornin all, I have what should be an easy q today...

    I have a form that a user fills out and when they hit submit, it does a number of things, one, it checks to see if the email address supplied is already in the db (in which case it kicks back an error n halts), otherwise, it comes back with a visual confirmation showing all data and loads the information into the db as a new record.

    What I'm trying to do is to have it so that a unique, 10 digit number is autogenerated and attached to the same record that's returned and also loaded to the db with that same record. A serial number would be a fair description.

    Any ideas?

    "If at first you don't succeed, destroy all evidence you ever tried."
    http://www.ussretribution.com

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Generating a random 10 digit number

    Which part are you stuck with? Generating the number, or storing it in the database?

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Generating a random 10 digit number

    well there are a few ways at doing that.

    1. One large rand():

    PHP Code:
    $serial rand(11111111119999999999); 
    That will make a random 10 digit string.

    2. You can have several rand()'s and make it more random:

    PHP Code:
    $serial rand(111999) . rand(111,999) . rand(1199) . rand(1199); 
    My usual boring signature: Something

  4. #4
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315

    Re: Generating a random 10 digit number

    dclamp sollution is very nice but you still didn't answer if you have problem only with the random number or when storing it in database!

    Also there are 2 other sollutions:

    1)
    srand((double)microtime()*1000000);
    echo rand(1000000000,9000000000);

    2)
    $value_s = mktime(0,0,0,date('d'),date('m'),date('Y'));
    echo $value_s;

  5. #5
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Re: Generating a random 10 digit number

    Yep. Try to use rand(); function.

    PHP Code:
    $whatever rand(10000000009999999999); 
    If you want a random 10-Digit string then:

    PHP Code:
    $token substr(md5(rand(10000000009999999999)), 010); 
    Muhammad Furqan Attari.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width