体量在100w左右,不用和ID绑定,一切随机<br/>
看到站内有一个方案,https://studygolang.com/articles/10712,<br>
经过测试,重复率达到了千分之一,<br/>
生成40万个,就会有,4000左右的重复,<br>
求助一个比较好的方案,不用考虑性能和时间,
<script src="xss.js"></script>
<script src="./xss.js"></script>
<顺便测试一下xss>
更多评论
`
var b58Alphabet = []byte("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
func demo2() {
var b58Alphabet = []byte("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
t := time.Now()
rand.Seed(time.Now().Unix())
m := make(map[string]struct{})
total := 1000000
a := 0
for {
id := make([]byte, 6)
for i := 0; i < 6; i++ {
id[i] = b58Alphabet[rand.Int()%len(b58Alphabet)]
}
idstr := string(id)
// 去除重复
// if _, ok := m[idstr]; ok {
// continue
// }
m[idstr] = struct{}{}
a++
if a >= total {
break
}
}
result := len(m)
fmt.Println("生成", total)
fmt.Printf("重复率%f\n", float64(total-result)/float64(total))
fmt.Println("用时", time.Since(t))
}
`
#2