Skip to content

math/rand: randFloat64() gives the same result irrespective of the number of times run #13718

@odeke-em

Description

@odeke-em

In the docs at https://golang.org/pkg/math/rand/#Float64, it says
screen shot 2015-12-23 at 5 24 18 am

However, I ran tests on both the playground http://play.golang.org/p/oK5GR_9Z_N and my computer
and it always gave me the same result 0.6046602879796196 no matter how many times I ran this. I found this out when testing out a program that simulates different sleep times to simulate contention for resources.

My test was:

$ cat randTest.go
package main

import (
    "log"
    "math/rand"
)

func main() {
    log.Println(rand.Float64())
}
$ go version >> randResult.txt && for i in $(seq 1 100); do sleep 0.25;go run randTest.go 2>> randResult.txt;done;cat randResult.txt | cut -d" " -f3 | sort | uniq
0.6046602879796196
devel

And from the playground
screen shot 2015-12-23 at 5 32 13 am

That is the exact same result I got from nacl and darwin.

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