随机数生成算法 [英] Random Number Generator Algorithm

查看:157
本文介绍了随机数生成算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 生成一个随机数。
  2. 验证是否数量已被分配。
  3. 如果是转到步骤1。
  4. 如果没有为新号码,并输出创建数据库记录的结果。

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

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:

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

  1. 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.

这篇关于随机数生成算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆