Go function multiple return values

In this example, we will show you how to write a function in Go to return multiple values.

Go functions allow to return of multiple values.

Go function multiple return values

In the example, we have a threerandom() function, which returns three random values.

package main

import (

func threerandom() (int, int, int) {

    x := rand.Intn(10)
    y := rand.Intn(10)
    z := rand.Intn(10)

    return x, y, z

func main() {

    r1, r2, r3 := threerandom()

    fmt.Println(r1, r2, r3)


0 8 7

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course