20// input data in custom size (height and width).
21func RandomImageWithSize(size int, data []byte) (image.Image, error) {
22 randExtent := len(palette.WebSafe) - 32
23 rand.Seed(time.Now().UnixNano())24 colorIndex := rand.Intn(randExtent)
25 backColorIndex := colorIndex - 1
26 if backColorIndex < 0 {
As math/rand
uses a statistical random number generator, using a low entropy
seed (such as constants and the current system time) may allow an attacker to
predict what the following number generated is.
package main
import (
"math/rand"
"time"
)
func main() {
rand.Seed(42) // constant seeds are bad
rand.Seed(time.Now().Unix()) // time based seeds don't have sufficient entropy
}