package main import ( "sync" log "git.staur.ca/stobbsm/simplelog" "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.Info("examples.CollisionChecks").Msg("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.Info("examples.collisionCheck"). Uint64("average iterations", total/runs). Int("runesize", runesize). Int("size", size). Send() } 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{}{} } }