Created
May 1, 2020 02:32
-
-
Save ZhangYet/f5a3c5ecf636a47b95a387f5fb171018 to your computer and use it in GitHub Desktop.
生成随机字符串并检查重复性
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 characters
package main | |
import ( | |
"fmt" | |
"github.com/dchest/uniuri" | |
) | |
func init() { | |
uniuri.StdChars = []byte("1234567890QWERTYUIOPASDFGHJKLZXCVBNM") | |
} | |
func main() { | |
record := map[string]bool{} | |
dup := 0 | |
limit := 100000000 | |
for i := 0; i < limit; i++ { | |
if i%100000 == 0 { | |
fmt.Printf("%d: dup: %d, dup rate: %f\n", i, dup, float64(dup)/float64(limit)) | |
} | |
s := uniuri.NewLen(9) | |
if _, ok := record[s]; ok { | |
dup += 1 | |
} else { | |
record[s] = true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment