Skip to content

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

Closed as not planned

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

Activity

  1. added this to the Unreleased milestone on Jul 27, 2023
  2. seankhliao commented on Jul 27, 2023

    @seankhliao
    Member

    see the deprecation notice for seeding

  3. locked and limited conversation to collaborators on Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions