Skip to content

math/rand: convenience functions always use the same seed (1). at least use time.Now() #16486

@ProhtMeyhet

Description

@ProhtMeyhet

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6.2 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
    globalRand in math/rand is always initialised with the constant seed 1. this is very unexpected. it should at least use time.Now().UnixNano() instead, else the random sequence is always the same.

even most of the go programmers didn't notice this. there are about 60 tests in the standard library that use "math/rand", but only 2 call rand.Seed() with time.Now(). as such they do not really test random, but the same sequence again and again.

  1. What did you expect to see?
    pseudo-random numbers, different with every call.
  2. What did you see instead?
    the same pseudo-random numbers on every call.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions