Make `FuzzUtilLimit` return random pieces of input set
MarvinJWendt opened this issue · 4 comments
Make FuzzUtilLimit
return random pieces of input set.
Hi @MarvinJWendt I was thinking of trying this one what do you think of something like that.
func FuzzUtilLimit[setType any](testSet []setType, limit int) []setType {
seen := map[int]bool{}
if len(testSet) <= limit {
return testSet
}
if limit <= 0 {
return []setType{}
}
var result []setType
counter := 0
for counter < limit {
index := rand.Intn(len(testSet) - 1)
if !seen[index] {
seen[index] = true
result = append(result, testSet[index])
counter++
}
}
return result
}
Hi @KarolosLykos, this would definitely work, but I am not sure if the performance might be better with rand.Shuffle
. We could then return a sub-slice of the shuffled slice (shuffledTestSet[:limit]
). If you want to benchmark both approaches, feel free to do so, otherwise I'll do it in the next weeks and get back to you with the result :)
Hey @MarvinJWendt , I ran some benchmarks and rand.Shuffle
is faster. Look at the benchmark tests and tell me what you think? benchmarks
I also included a PR with the proposal.
Fixed in #200 and released with v0.5.2
. Thanks!