Question

In: Computer Science

what is a good hash function for ID numbers of format "LM-0001312", "LM-04341313", "LM-4205114"

what is a good hash function for ID numbers of format "LM-0001312", "LM-04341313", "LM-4205114"

Solutions

Expert Solution

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.


Related Solutions

You want to create a good hash function. Which of these properties is the least important...
You want to create a good hash function. Which of these properties is the least important for your hash function to have? Let's say you want to store a collection of unique elements. You would like to be able to search, insert, delete as fast as possible. Which data structure should you use? Let's say you want your hash table to allow load factors greater than 1. You would use:
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the...
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the keys 41, 16, 40, 47, 10, 55. Assuming collisions are handled by Double hashing. SHOW WORK
3. Draw the hash table that results using the hash function: h(k)=kmod 7 to hash the...
3. Draw the hash table that results using the hash function: h(k)=kmod 7 to hash the keys 50, 700, 76, 85, 92, 73, 101. Assuming collisions are handled by Quadratic probing. Don't write a program. Just please manually solve the problem. Thanks.
Are hash algorithms (such as MD5 and SHA1) are as good as they appear to be?...
Are hash algorithms (such as MD5 and SHA1) are as good as they appear to be? Why or why not?
C# Programming create a Hash Function
C# Programming create a Hash Function
Develop an algorithm to demonstrate hashing using hash table with modulo as the hash function. Assume...
Develop an algorithm to demonstrate hashing using hash table with modulo as the hash function. Assume the size of the hash table as 10. To avoid collisions in case of identical keys for two different elements, use Linear Probing collision resolution technique. using c++ add comment on the code
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any...
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any desired date as the salt. Demonstrate operation of the function, including input values. Describe benefits and shortcomings of the hash function.
Why is it not good to directly store the hash of password in a file? How...
Why is it not good to directly store the hash of password in a file? How can the use of salt enhance password security?
Is MD5 hash function is indistinguishable and non-malleable? Explain it.
Is MD5 hash function is indistinguishable and non-malleable? Explain it.
1. Prepare in good format, an income statement. 2. Prepare in good format, a statement of...
1. Prepare in good format, an income statement. 2. Prepare in good format, a statement of owner’s equity. 3. Prepare a classified year-end balance sheet. (Note: A $9,000 installment on the long-term note payable is due within one year.) Account Debit Credit Cash $ 112,000 Accounts receivable 27,000 Prepaid rent 15,000 Prepaid Insurance 9,000 Office supplies 3,300 Office equipment 38,000 Accumulated depreciation–Equipment $3,200 Building 288,000 Accumulated depreciation–Building 42,000 Land 700,000 Accounts payable 25,800 Salaries payable 14,500 Interest payable 2,500 Long-term...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT