Skip to content

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

@AlexBaranowski

Description

@AlexBaranowski

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())

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions