Skip to content

Instantly share code, notes, and snippets.

@astaxie
Created July 17, 2012 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astaxie/3128236 to your computer and use it in GitHub Desktop.
Save astaxie/3128236 to your computer and use it in GitHub Desktop.
golang rand list
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
fmt.Println("Hello, playground")
fmt.Println(randList(1, 15))
}
func randList(min, max int) []int {
if max < min {
min, max = max, min
}
length := max - min + 1
t0 := time.Now()
rand.Seed(int64(t0.Nanosecond()))
list := rand.Perm(length)
for index, _ := range list {
list[index] += min
}
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment