2 years ago

#64637

test-img

sagar verma

custom hashing algorithm to generate unique id using some alphanumeric string

I will need to generate one unique id with all digits, using some hashing algorithm. Currently I am having some base64 encoded id like "BTS_MDEyMzQ1Njc4OQ==_1". I wanted to generate the unique-id using this string. I have used the below algorithm to generate, however it does not look very promising. There are many chances that the duplicate id number can be generated as unique-id using this algorithm. Ref: https://opendsa-server.cs.vt.edu/ODSA/Books/CS3/html/HashFuncExamp.html

static int hashing(String x) {
    char ch[];
    ch = x.toCharArray();
    int xlength = x.length();

    int i, sum;
    for (sum=0, i=0; i < x.length(); i++) {
        sum += ch[i];
    }
    return sum;
}

Can someone please suggest if there is easy simple solution available.

java

algorithm

hash

hashcode

0 Answers

Your Answer

Accepted video resources