diff --git a/util.go b/util.go index 5f210af..0512944 100644 --- a/util.go +++ b/util.go @@ -8,6 +8,31 @@ import ( // from http://stackoverflow.com/a/31832326 var src = rand.NewSource(time.Now().UnixNano()) +const letterBytes = "abcdefghijklmnopqrstuvwxyz1234567890" +const ( + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + + return string(b) +} + var mimeToExtension = map[string]string{ "application/andrew-inset": "ez", "application/applixware": "aw", @@ -777,28 +802,3 @@ var mimeToExtension = map[string]string{ "video/x-smv": "smv", "x-conference/x-cooltalk": "ice", } - -const letterBytes = "abcdefghijklmnopqrstuvwxyz1234567890" -const ( - letterIdxBits = 6 // 6 bits to represent a letter index - letterIdxMask = 1<= 0; { - if remain == 0 { - cache, remain = src.Int63(), letterIdxMax - } - if idx := int(cache & letterIdxMask); idx < len(letterBytes) { - b[i] = letterBytes[idx] - i-- - } - cache >>= letterIdxBits - remain-- - } - - return string(b) -}