Programming Language: Golang

Namespace/Package Name: math/rand

Class/Type: Rand

Method/Function: Int31n

Examples at hotexamples.com: 17

The Go programming language comes bundled with a math/rand library that provides support for pseudo-random number generation.

One of the functions provided by this package is RandInt31n, which returns a non-negative 31-bit integer in the range [0, n).

Here's an example usage of RandInt31n, where we generate a random number between 0 and 100:

One of the functions provided by this package is RandInt31n, which returns a non-negative 31-bit integer in the range [0, n).

Here's an example usage of RandInt31n, where we generate a random number between 0 and 100:

package main import ( "fmt" "math/rand" ) func main() { rand.Seed(time.Now().UnixNano()) // Generate a random number between 0 and 100 randNum := rand.Int31n(100) fmt.Printf("Random number between 0 and 100: %v", randNum) }In this example, we first seed the random number generator using the current time. Then, we generate a random number between 0 and 100 using the RandInt31n function. Finally, we print the generated number to the console. The package library used in this example is the standard math/rand library provided by Go.

Frequently Used Methods

Frequently Used Methods

Related

Related in langs