Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Random

  • rand

  • Float64

  • Int

  • Intn

  • Pseudo Random

  • rand

  • Go will always start from the same random seed of 1 meaning that this script will always generate the same "random" numbers.

package main

import (
	"fmt"
	"math/rand"
)

func main() {
	x := rand.Float64()
	fmt.Println(x)

	y := rand.Int()
	fmt.Println(y)

	a := rand.Intn(10) // between [0, n)
	fmt.Println(a)
	b := rand.Intn(10) // between [0, n)
	fmt.Println(b)

}
0.6046602879796196
8674665223082153551
7
9