我们大多数人都看到,当我们从类似亚马逊的网站上进行购买时,我们会得到一个订单号或购买号(10-12 位数字),它看起来像一些随机数。同样,我想为大型系统生成唯一 ID。生成它的最佳算法是什么?
一些我认为效率不高或不适用于大规模系统的方法
1) Generating string using rand function ( Array.new(12){rand(10)}.join) and checking
whole table whether it is exists. It is time consuming, inefficient and may struck
in infinite loop.
2) Using time-stamp - I think this cannot be used for large scale system because large
no. user can excess system at same time.
3) Combination of 1) & 2) also creates issue as second when it generates same 1)
Auto increment : I don't want to use.