Created
March 11, 2016 08:28
Revisions
-
kevinkindom created this gist
Mar 11, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # 随机文件名长度算法 通过当前时间可计算出随机的长度文件算法,结合先前的文件名md5算法得出: > **00 - 04 区间**:使用目前16位MD5 > **05 - 16 区间**:使用32位md5,例目前是05分,则从md5字符串第0个字符截取到第五个字符,共5个字符做文件名 > **17 - 59 区间**:使用当前分钟数和16求余,得到的值再匹配上述两条规则即可,例如 例1:目前是17分,和16求余是1(相当于01分),匹配到了00-04的区间,则使用16位长度的文件名 例2:目前是38分,和16求余是6(相当于06分),匹配到了05-16的区间,则使用5位长度的文件名 下以javascript代码举例: ``` javascript // md5 为32位,minutes为当前时间的分钟 var getFilename = function(md5, minutes){ var minutes = parseInt(minutes); if(minutes <= 4){ return md5.slice(0, 16); }else if(minutes <= 16){ return md5.slice(0, minutes); }else{ return getFilename(md5, minutes % 16); } } ```