package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) num := rand.Float32() * 6 // Roll a dice fmt.Println(num) }
package main import ( "fmt" "math/rand" "time" ) func main() { rand.Seed(time.Now().UnixNano()) red := rand.Float32() green := rand.Float32() blue := rand.Float32() fmt.Printf("#%02x%02x%02x\n", int(red*255), int(green*255), int(blue*255)) }This code uses the `Rand.Float32()` function to generate random values for red, green, and blue color channels and then formats them as an RGB hexadecimal code. Both examples use the `math/rand` package in Go to generate random numbers.