Generating unique ids with the max length of 3 digits/letters/simbols

前端 未结 3 1662
迷失自我
迷失自我 2021-01-17 08:12

I have a list of 75200 words. I need to give a \'unique\' id to each word, and the length of each id could be 3 letters or less. I can use numbers, letters or even symbols b

3条回答
  •  悲&欢浪女
    2021-01-17 08:20

    (Posted on behalf of the question author).

    This is how I wrote my code according to the answer of Stack Overflow user "Keppil".

    import java.io.*;
    import java.util.*;
    
    public class HashCreator 
    {
        private Map completedWordMap;
        private String[]simpleLetters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        private char[] A;
    
            private static final String[] symbols = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h",
            "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "^", "&",
            "*", "~", "?" };
    
        public HashCreator()
        {
    
             for(int i=0;i<75001;i++)
             {
                System.out.println(getSequence(i));
             }
        }
    
    
    
    
        public static String getSequence(final int i) {
        return symbols[i / (symbols.length * symbols.length)] + symbols[(i / symbols.length) % symbols.length]
                + symbols[i % symbols.length];
    }
    }
    

提交回复
热议问题