Skip to content

Instantly share code, notes, and snippets.

@ZhangYet
Created May 1, 2020 02:32
Show Gist options
  • Save ZhangYet/f5a3c5ecf636a47b95a387f5fb171018 to your computer and use it in GitHub Desktop.
Save ZhangYet/f5a3c5ecf636a47b95a387f5fb171018 to your computer and use it in GitHub Desktop.
生成随机字符串并检查重复性
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