talos/pkg/startup/rand.go
Andrew Rynhard d430a37e46 refactor: use go 1.13 error wrapping
This removes the github.com/pkg/errors package in favor of the official
error wrapping in go 1.13.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
2019-10-15 22:20:50 -07:00

26 lines
558 B
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package startup
import (
"fmt"
cryptorand "crypto/rand"
"encoding/binary"
"math/rand"
)
// RandSeed default math/rand PRNG.
func RandSeed() error {
seed := make([]byte, 8)
if _, err := cryptorand.Read(seed); err != nil {
return fmt.Errorf("error seeding rand: %w", err)
}
rand.Seed(int64(binary.LittleEndian.Uint64(seed)))
return nil
}