Skip to content

x/website: Problem with random greetings source not initialized #61606

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

Closed
AlexBaranowski opened this issue Jul 27, 2023 · 1 comment
Closed

Comments

@AlexBaranowski
Copy link

What is the URL of the page with the issue?

https://go.dev/doc/tutorial/random-greeting

What is your user agent?

Does not matter

Screenshot

Does not matter

What did you do?

The greetings example uses:

    return formats[rand.Intn(len(formats))]

Without initializing the source/seed for random entropy.

What did you expect to see?

The provided example code returns random values.

What did you see instead?

Same output every time when I run

go run .

on hello module from tutorial.

It can be fixed by changing original code the

import (
    "errors"
    "fmt"
    "math/rand"
    "time"
)
func Hello(name string) (string, error) {
    rand.Seed(time.Now().UnixNano())

@gopherbot gopherbot added this to the Unreleased milestone Jul 27, 2023
@seankhliao
Copy link
Member

see the deprecation notice for seeding

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2023
@golang golang locked and limited conversation to collaborators Jul 26, 2024
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