Skip to content

Instantly share code, notes, and snippets.

@atulsingh0
Last active September 20, 2022 22:54
Show Gist options
  • Save atulsingh0/e247ca8e8a1918a7abf021051bd07afd to your computer and use it in GitHub Desktop.
Save atulsingh0/e247ca8e8a1918a7abf021051bd07afd to your computer and use it in GitHub Desktop.
Math/Rand or Crypto/Rand Package - Golang
// Go Playground
// https://go.dev/play/p/enEBiI2_5hd
package main
import (
"fmt"
"math/rand"
"sort"
"time"
)
func main() {
fmt.Println(genRandomList(20, 100))
}
func genRandomList(num int, max int) []int {
var random_list []int
rand.Seed(time.Now().UnixNano())
for i := 0; i < num; i++ {
// Geneate the random no between 0 to max
random_list = append(random_list, rand.Intn(max))
}
// sorting data
sort.Ints(random_list)
return random_list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment