podman/libpod/runtime_pre_go1.20.go
Chris Evich 221e3023f6
Fix rand.Seed() deprecation in golang 1.20
Ref: https://pkg.go.dev/math/rand@go1.20#Seed

Note: For `runtime_test.go`, this test-case was never actually doing
what appears as it's intent .  Fixing it to work as intended would be
require incredibly libpod-invasive changes.  Do the least-worse thing and
simply confirm that consecutive generated names are different.

Signed-off-by: Chris Evich <cevich@redhat.com>
2023-04-26 14:55:03 -04:00

19 lines
418 B
Go

// In go 1.20 and later, the global RNG is automatically initialized.
// Ref: https://pkg.go.dev/math/rand@go1.20#Seed
//go:build !go1.20
// +build !go1.20
package libpod
import (
"math/rand"
"time"
)
func init() {
// generateName calls namesgenerator.GetRandomName which the
// global RNG from math/rand. Seed it here to make sure we
// don't get the same name every time.
rand.Seed(time.Now().UnixNano())
}