简体   繁体   English

Java算法创建自己的唯一密钥

[英]Java algorithm to create own unique key

I want to create an own unique key which is 6 characters long and includes the following regex characters and numbers: [az][0-9] eg: 00000A, 00000B, ... 00000Z, 00001A, 00001B,...我想创建一个自己的唯一密钥,长度为 6 个字符,包括以下正则表达式字符和数字:[az][0-9] 例如:00000A, 00000B, ... 00000Z, 00001A, 00001B,...

I don't know how to create this algorithm of these regex formation.我不知道如何创建这些正则表达式的算法。

Has someone an idea, how to create this algorithm?有人有想法,如何创建这个算法?

First, your regexp does not match the numbers you're showing as examples.首先,您的正则表达式与您作为示例显示的数字不匹配。 So you'd need to make up your mind there :)所以你需要在那里下定决心:)

Second, you can simply use a base-36 number probably, and somehow keep track of the last number generated (eg using a properties file or database field) in a synchronized singleton.其次,您可以简单地使用 base-36 数字,并以某种方式跟踪同步单例中生成的最后一个数字(例如,使用属性文件或数据库字段)。

Then create a simple method that turns the number into a String and left pad that number with zeros until you reach the desired length.然后创建一个简单的方法,将数字转换为字符串,并用零填充该数字,直到达到所需的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM