mirror of
https://github.com/onyx-and-iris/lottery-cli.git
synced 2026-08-17 00:34:25 +00:00
initial commit
This commit is contained in:
19
util.go
Normal file
19
util.go
Normal file
@@ -0,0 +1,19 @@
|
||||
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, max int) []int {
|
||||
perm := rand.Perm(max)
|
||||
result := make([]int, count)
|
||||
for i := range result {
|
||||
result[i] = perm[i] + 1
|
||||
}
|
||||
sort.Ints(result)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user