package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) fmt.Println(rand.Float64()) }
0.7292459645420822
package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) lowerBound := 1.0 upperBound := 10.0 randomNum := lowerBound + rand.Float64()*(upperBound-lowerBound) fmt.Println(randomNum) }
7.039421919958845In both examples, we used the "math/rand" package to generate a random float64 number. We also used the "time" package to seed the random number generator, which ensures that we get a different sequence of random numbers each time we run the program.