如何生成的12位唯一号码? [英] How to generate unique number of 12 digits?
问题描述
我正在发送原始数据斑马打印机并打印出条码的应用程序。 。而且,由于每个项目都有其独特的条形码,我需要定义一个自动生成的长12位的唯一编号的变量
I'm working on an app that sends raw data to zebra printer and print out barcodes. And since every item has its own unique barcode, I need to define a variable that automatically generates unique number of 12 digits long.
见例如:
printBar prnt = new printBar("123456789012");
反正是有定义一个双变量,并传递给函数返回uniqely 12位号码,再次将它传递给printBar类?但是,如何确保每次你访问它返回一个独特的价值?
Is there anyway to define a double variable and pass it to a function that return uniqely 12 digits number and pass it over again to the printBar class?. But how to make sure everytime you access it returns a unique value?.
我又想到了另一种方式,因为使用MS Access数据库是,我可以创建一个列自动编号数据类型,并将其分配给随机的,但你没有得到所需的精确12位,有时它产生的10位有时或多或少的值。
I also thought of another way, since am using MS Access db, I can create a column of AutoNumber datatype and assign it to Random, but you don't get the exact 12 digits required, sometimes it generates a value of 10 digits sometimes more or less.
推荐答案
使用RNG和一个哈希做:
10 - 流出来12位
20 - 检查是否值是哈希
30 - 如果它转到其他40 10转到
40 - 推值转换成散列
50 - 返回新的12位数字
60 - 10跳转
Using an RNG and a hash do:
10 - stream out 12 digits
20 - check if value is in hash
30 - if it's goto 40 else goto 10
40 - push value into hash
50 - return new 12 digit number
60 - goto 10
这篇关于如何生成的12位唯一号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!