package main import ( "log" "sync" "git.staur.ca/stobbsm/tind" ) var ( RuneSet = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}/';:.>,<`~") ) const runs uint64 = 10000 // CollisionChecks runs different tests to check for collisions, and get's the average func CollisionChecks() { wg := new(sync.WaitGroup) log.Println("Using multiple configurations, test for collisions multiple times") sizes := []int{4,5,6,7,8,9,10,11,12,13,14,15,16} end := len(RuneSet) for i := 4; i < end; i++ { for _, v := range sizes { v := v rs :=RuneSet[:i] wg.Add(1) go collisionCheck(v, rs, wg, len(rs)) } } wg.Wait() } func collisionCheck(size int, runeset []rune, wg *sync.WaitGroup, runesize int) { defer wg.Done() var total uint64 for i := uint64(0); i < runs; i++ { total += runCheck(tind.New().WithSize(size).WithRuneset(runeset)) } log.Printf("runset size: %d, id size: %d, average iterations before collision: %d", runesize, size, total/runs) } func runCheck(tconfig *tind.Config) uint64 { var i uint64 tmap := make(map[string]struct{}) for { i++ t := tconfig.Gen() if _, ok := tmap[t.String()]; ok { return i } tmap[t.String()] = struct{}{} } }