随机数生成算法随机数、算法

2023-09-11 23:01:39 作者:喝着农药吐泡泡o○

什么算法生成随机数像(信用卡/借记卡号码)使用的银行?

What algorithm is used by banks for generating random numbers like(credit cards/debit cards numbers) ?

假设我维护所有的号码数据库,如果我尝试下面的方法,

Suppose i maintain all the numbers in DB and If i try the below approach,

生成一个随机数。 验证是否数量已被分配。 如果是转到步骤1。 如果没有为新号码,并输出创建数据库记录的结果。

这会带来更多的点击分贝时,发卡量的增加。

It will ask for more db hits when the card volume increases.

任何其他担此?请大家帮帮忙。

Any other take on this ?? Please help.

推荐答案

一般有三种解决方案,以非重复的随机数的问题:

There are three general solutions to the non-duplicate random number problem:

如果你从一个大范围的要几号,然后选择一个并拒绝它,如果它是一个重复。如果该范围大,那么这将不会造成太多的反复尝试。这是你提什么上面。

If you want a few numbers from a large range then pick one and reject it if it is a duplicate. If the range is large, then this won't cause too many repeated attempts. This is what you mention above.

如果你从一个小范围的想了很多的数字,然后将所有的数字阵列中的和随机的数组。该费雪耶茨算法是标准数组洗牌。采取随机数的洗牌阵列序列。

If you want a lot of numbers from a small range, then set out all the numbers in an array and shuffle the array. The Fisher-Yates algorithm is standard for array shuffling. Take the random numbers in sequence from the shuffled array.

如果你从一个大范围的想了很多的数字,然后使用适当大小的加密算法。例如。为64位数字使用DES加密和0,1,2,3,...的顺序。输出保证独一无二的,因为加密是可逆的。该冬冬布丁密码可以为任何方便的数字范围进行设置。

If you want a lot of numbers from a large range then use an appropriately sized encryption algorithm. E.g. for 64 bit numbers use DES and encrypt 0, 1, 2, 3, ... in sequence. The output is guaranteed unique because encryption is reversible. The Hasty Pudding Cipher can be set for any convenient range of numbers.