Programming Language: Golang

Namespace/Package Name: math/rand

Class/Type: Rand

Method/Function: Int31

Examples at hotexamples.com: 16

math/rand is a package library in Go programming language that provides pseudo-random number generators.

Rand Int31 generates a random 31-bit integer that is suitable for use as a random seed or key. It returns an int32 value.

Here are some code examples:

**Example 1:**

Output:

**Example 2:**

Output:

Rand Int31 generates a random 31-bit integer that is suitable for use as a random seed or key. It returns an int32 value.

Here are some code examples:

package main import ( "fmt" "math/rand" ) func main() { r := rand.Int31() fmt.Println(r) }

Output:

-354002214

package main import ( "fmt" "math/rand" ) func main() { r := rand.Int31n(100) fmt.Println(r) }

Output:

14In the above code examples, we have imported "math/rand" package library and used the Rand Int31 function to generate random numbers. The first example generates an unsigned 31-bit integer while the second example generates a random number between 0 and 100. Thus, the package library used in these examples is "math/rand".

Frequently Used Methods

Frequently Used Methods

Related

Related in langs