Skip to content

How to Generate a Random Int Over a Range (func)

In Golang, there is no function to generate random numbers over a range! Writing a random generator function is easy and I wrote one for you.

Enjoy this simple example:

package main

import (

func main() {
	min := 10
	max := 100

	fmt.Println(randInt(min, max))

func randInt(min, max int) int {

	return rand.Intn(max-min+1) + min


Leave a Reply

Your email address will not be published. Required fields are marked *