Results 1 to 2 of 2

Thread: Generate 10 Digit unique number

  1. #1
    Join Date
    Aug 2010
    Posts
    2

    star Generate 10 Digit unique number

    Generate 10 Digit unique number on Date
    Use the following code for creating 10 digit unique number on the basis of dates. It is unique in seconds level not design for milliseconds.
    this program will create unique numbers upto 52 years, reset it with changing 'adder' value.

    Author : Sunil Wagh (SCJP, SCWCD, OCP , IBM Maximo 7 Certified)
    --------------------------------------------------------------------------
    import java.text.DecimalFormat;
    import java.util.Calendar;

    public class Demo2 {
    // truncate four digit to two digit 2010=>10
    public static int retval(int y){
    String yrs=""+y;
    yrs=yrs.substring(1);
    y = Integer.parseInt(yrs) ;
    return y;
    }
    // Create 10 Digit Unique number
    public void test(){
    int adder = 55;//Number Start from year 2010, change 64 to start from 2001
    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int doy = cal.get(Calendar.DAY_OF_YEAR);
    int hr = cal.get(Calendar.HOUR_OF_DAY);
    int mi = cal.get(Calendar.MINUTE);
    int ss = cal.get(Calendar.SECOND);
    int yr = adder+retval(year);
    char c=(char)yr;
    DecimalFormat df = new DecimalFormat("000");
    System.out.println("Unique Num: " + c + df.format(doy) + hr + mi + ss);
    }

    public static void main(String a[]){
    Demo2 d = new Demo2();
    d.test();
    }
    }
    -------------------------------------------------------------------------
    Output : Unique Num: A23117587
    ------------------------------------------------------------------------

  2. #2
    Join Date
    Dec 2007
    Posts
    996

    Re: Generate 10 Digit unique number

    Thanks for the code, however I was needing a script, where basically the user has to enter his name, choose file, file comments if required and upload and I want to generate a 10 digit unique code everytime, which makes it simple for the user to download the file. I am posting the below code, can you help me out:

    PHP Code:
    <?
    //set the random id length 
    $random_id_length 10
    //generate a random id encrypt it and store it in $rnd_id 
    $rnd_id crypt(uniqid(rand(),1)); 
    //to remove any slashes that might have come 
    $rnd_id strip_tags(stripslashes($rnd_id)); 
    //Removing any . or / and reversing the string 
    $rnd_id str_replace(".","",$rnd_id); 
    $rnd_id strrev(str_replace("/","",$rnd_id)); 
    //finally I take the first 10 characters from the $rnd_id 
    $rnd_id substr($rnd_id,0,$random_id_length); 
    echo 
    "Random Id: $rnd_id"
    ?>

Similar Threads

  1. Adding digit in front of number in cell in Microsoft Excel
    By Thedevotee in forum MS Office Support
    Replies: 2
    Last Post: 07-02-2012, 07:45 PM
  2. Replies: 2
    Last Post: 01-02-2012, 07:10 PM
  3. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  4. Generate unique four digit number
    By Bhadrak in forum Software Development
    Replies: 3
    Last Post: 19-08-2010, 06:10 PM
  5. 4-Digit Number Code (0-9)
    By christheart in forum Off Topic Chat
    Replies: 3
    Last Post: 03-07-2009, 10:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,278,875.16374 seconds with 17 queries