Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links

Generate 10 Digit unique number

Software Development

Thread Tools Search this Thread
Old 19-08-2010
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;
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();
Output : Unique Num: A23117587

Reply With Quote
Old 20-08-2010
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); 
"Random Id: $rnd_id"
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , , , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Generate 10 Digit unique number"
Thread Thread Starter Forum Replies Last Post
Adding digit in front of number in cell in Microsoft Excel Thedevotee MS Office Support 2 07-02-2012 06:45 PM
How to make Microsoft Excel to stop rounding out 16 digit number Talisha MS Office Support 2 01-02-2012 06:10 PM
Generate some quality of random number via Random Number Generation function aMADeO! Windows Software 4 13-01-2012 04:07 PM
Generate unique four digit number Bhadrak Software Development 3 19-08-2010 06:10 PM
4-Digit Number Code (0-9) christheart Off Topic Chat 3 03-07-2009 10:32 AM

All times are GMT +5.5. The time now is 09:55 PM.