Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hash/hasmap - Allow Creation of a Fixed Seed #43043

Closed
tebeka opened this issue Dec 7, 2020 · 2 comments
Closed

hash/hasmap - Allow Creation of a Fixed Seed #43043

tebeka opened this issue Dec 7, 2020 · 2 comments

Comments

@tebeka
Copy link
Contributor

tebeka commented Dec 7, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/miki/.cache/go-build"
GOENV="/home/miki/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/miki/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/miki/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/miki/work/ardanlabs/gotraining/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build588961670=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm testing a code that uses hash/maphash, since there's no way to create a fixed seed the test randomly fails.

What did you expect to see?

I'd like to have a way to create a fixed Seed (like there is in math/rand)

What did you see instead?

No way to create a fixed seed.

@randall77
Copy link
Contributor

This feature is intentionally missing. Providing a way to generate a reproducible seed means we're locked into a hashing algorithm (a historical problem we've had with math/rand, see for example #8013) .

If you need fixed seed behavior for reproducing a test, you will need to build a mock of the hasher and use that while testing.

Conceivable the stdlib could provide that mock and declare a common interface, but I'd like to see it developed outside the stdlib first.

@tebeka
Copy link
Contributor Author

tebeka commented Dec 7, 2020

Thanks for the explanation @randall77

@golang golang locked and limited conversation to collaborators Dec 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants