on 05-16-2007 8:25 AM
hi experts,
according to our requirement we have to generate a unique acknowledgement number for an online application form. It purpose is simlar to an online exams form where we get the acknowledgement number to trace the status of our form once we submit it
we are building application in SAP EP (webdynpro)
with warm regards
vijai
Vijay,
one more easy way is to use, <b>Math.random()</b> function,
Suppose you want to generate a unique 5 digit number,
int uniqueCode = (int) (Math.random() * 90000 + 10000);
hope it helps!!!
Regards
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hai Vijay.
Wherever you required to generate Unique Id just call the method getUniqueId
Place this codee under
@@begin others
@@end
public String getUniqueId() {
try {
SecureRandom objSecureRandom = SecureRandom.getInstance("SHA1PRNG");
String randomNumber = new Integer( objSecureRandom.nextInt() ).toString();
MessageDigest objMessageDigest = MessageDigest.getInstance("SHA-1");
byte[] result = objMessageDigest.digest( randomNumber.getBytes() );
return encodeHexaDecimal(result);
}
catch ( NoSuchAlgorithmException ex ) {
System.err.println(ex);
return null;
}
}
private String encodeHexaDecimal( byte[] aInput){
StringBuffer buffer = new StringBuffer();
char[] digits = {'0', '1', '2', '3', '4','5','6','7','8','9','a','b','c','d','e','f'};
for ( int idx = 0; idx < aInput.length; ++idx) {
byte b = aInput[idx];
buffer.append( digits[ (b&0xf0) >> 4 ] );
buffer.append( digits[ b&0x0f] );
}
return buffer.toString();
}
Regards,
Naga
I would avoid Deepak's & Naga's solution as they are based on random number generation... the output of which are pseudo-random, but not at all guaranteed to be unique.
Denis' suggestion seems more appropriate here - UIDs & VMIDs were designed to be unique, not just random. I think that is what you are looking for.
Vijay,
Make use of Java persistence, create storage for a number eg. 100,000 (Assume this as the start number), fetch that number every time application is submitted, increment it by one and assign it as the acknowledgement number. Also update the database back with the new value.
I think this will solve your problem,
So whenever user submits the application, will get the new number (incremented) as the acknowledgment number.
Regards
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There are pair of little known classes called java.rmi.server.UID and java.rmi.dgc.VMID.
The UID class can generate identifiers that are unique over time within a JVM. The VMID class is even cooler - it provides uniqueness across ALL JVM's.
For the detail heads, UID consists of a unique number based on a hashcode, system time and a counter, and a VMID contains a UID and adds a SHA hash based on IP address.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.