Files
obitools4/pkg/obistats/random.go
Eric Coissac 077f3b5bb5 first trial of obilandmark
Former-commit-id: 00a50bdbf407b03dfdc385a848a536559f5966a5
2023-08-25 23:23:23 +02:00

26 lines
335 B
Go

package obistats
import "math/rand"
func SampleIntWithoutReplacemant(n, max int) []int {
draw := make(map[int]int, n)
for i := 0; i < n; i++ {
y := rand.Intn(max)
x, ok := draw[y]
if ok {
y = x
}
draw[y] = max - 1
max--
}
res := make([]int, 0, n)
for i := range draw {
res = append(res, i)
}
return res
}