mirror of
https://github.com/onyx-and-iris/lottery-cli.git
synced 2026-08-17 00:34:25 +00:00
20 lines
476 B
Go
20 lines
476 B
Go
package lottery
|
|
|
|
import (
|
|
"math/rand"
|
|
"sort"
|
|
)
|
|
|
|
// drawUnique returns count unique numbers in the range [1, max].
|
|
// It uses the rand.Perm function to generate a random permutation of numbers and selects the first count numbers from it.
|
|
// The result is sorted before being returned.
|
|
func drawUnique(count, maxNum int) []int {
|
|
perm := rand.Perm(maxNum)
|
|
result := make([]int, count)
|
|
for i := range result {
|
|
result[i] = perm[i] + 1
|
|
}
|
|
sort.Ints(result)
|
|
return result
|
|
}
|