生成唯一的ID(检查或没有)? [英] Generating unique ID's ( check or not )?

查看:133
本文介绍了生成唯一的ID(检查或没有)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到YouTube的视频网址(例如):

Considering youtube video url (for example):

例如。

http://www.youtube.com/watch?v=-JVkaMqD5mI&feature=related

我说的是 -JVkaMqD5mI 部分。 (长度= 11)

I'm talking about the -JVkaMqD5mI part. ( length=11)

让calc下的选项:

a-z = 26     |
A-Z = 26     |_______ >    26+26+10+2 = 64 optional chars in 11 places  = 64^11 = 73786976294838206464
0-9 = 10     |
-_ = 2       |

我还在纳闷,当他们产生了一个新的视频一个新的ID,难道他们还是检查的已经存在的?

我敢肯定,他们有一些名单(dB或缓存)了的已经生成的ID的的......(如果他们这样做,他们做的每一次AQUIRE分贝?还是缓存?或...?)

Im sure they have some list( db or cache) of the "already generated ID's" ... ( and if they do , do they aquire the db each time ? or in cache ? or...?)

还是他们靠 1.355252 ... E-20 机会这几乎是 0 。(但还在!= 0)

Or do they rely on the 1.355252...e-20 chances which is almost 0.( but still !=0)

什么是最好的实践解决方案对于​​这种情况?

What is the best practice solutions for this kind of situations ?

推荐答案

好了,只是因为他们使用的是对视频的字母数字ID,并不意味着他们仅仅是产生这些字符是随机的。仅仅因为这个字符串看起来就像是随机的垃圾你,我向你保证这不是随机的,有很多藏在里面的信息。

Well, just because they are using an alphanumeric ID on the video, does not mean they are simply generating those characters at random. Just because that string looks like random garbage to you I assure you it is not random and there is lots of information hidden in there.

这么快的回答:不,它不是feasable生成的字母随机序列然后是一个),希望没有冲突或b)通过可能是数十亿条记录检查,看看是否你已经有一个

So quick answer: No, it is not feasable to generate a random sequence of letters then either a) hope for no collisions or b) check through possibly billions of records to see if you already have that.

更容易保持一个中央上次使用的ID,并有一种算法,从为下一个ID用在数学上保证产生一个previously未使用的ID的方式上一次使用的ID移动。在连续的ID号的情况下,这个公式很简单的 F(N + 1)= F(N)+1 (如上次使用的ID为150,下一个会是151 ..保证不用这样远),但你可以设计自己的配方,以满足您的需求。

Much easier to keep a central "last ID used" and have an algorithm that moves from "last ID used" to "next ID to use" in a way that is mathematically guaranteed to generate a previously unused ID. In the case of sequential ID numbers that formula is simply f(n+1) = f(n)+1 (eg. last ID used was 150, next one will be 151.. guaranteed unused so far) but you can devise your own formulas to suit your needs.

这篇关于生成唯一的ID(检查或没有)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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