In: Computer Science
what is a good hash function for ID numbers of format "LM-0001312", "LM-04341313", "LM-4205114"
To solve this problem i have implemented a java program named CodeGenerate.java
This program will take the number of ID_NUMBER format required as input and print all the corresponding ID_NUMBER in output.
CodeGenerate.java
import java.util.Random;
import java.util.Scanner;
public class CodeGenerate {
private String[] hashCodes;
// Creating HashCodes
public void hashFunctionOfIdNumber(int
noOfCode){
hashCodes = new
String[noOfCode];
for(int i=0; i<noOfCode;
i++){
// Generating a
Random number within range 1000000 to 9999999
Random rnd = new
Random();
int n = 1000000
+ rnd.nextInt(9999999);
StringBuilder b
= new StringBuilder(); // Initialize a
StringBuilder
b.append("LM-");
b.append(n);
hashCodes[i] =
b.toString();
}
}
//Display all the HashCodes
public void printHashCodes(){
for(int i=0; i<hashCodes.length;
i++){
System.out.println(hashCodes[i]);
}
}
public static void main(String[] args) {
CodeGenerate obj = new
CodeGenerate();
Scanner in = new
Scanner(System.in);
int noOfCode = in.nextInt();
obj.hashFunctionOfIdNumber(noOfCode);
obj.printHashCodes();
}
}
Output
5 (Input)
LM-7729511
LM-1065575
LM-8765427
LM-3010207
LM-4670459
In case any further information required please let me know.