.Maui Blog

Golang | Get a random number within a range

package main

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)

func random(min, max int) int {
	rand.Seed(time.Now().UTC().UnixNano())
	return rand.Intn(max-min) + min
}

func main() {

	myrand := random(1, 91)
	fmt.Println(strconv.Itoa(myrand))
    
}
Exit mobile version