Created
July 17, 2012 09:11
-
-
Save astaxie/3128236 to your computer and use it in GitHub Desktop.
golang rand list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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