Go: use of a deprecated function in an exercise

From Randomness page on Exercism, the last section of the page:

If you don’t call rand.Seed, then the package will produce the same sequence of random numbers each time your program runs!

and the related Animal Magic exercise:

1. Seed the random number generator.
Implement a SeedWithTime function that seeds the math.rand package with the current computer time.

From rand package documentation:

If Seed is not called, the generator is seeded randomly at program startup.
Prior to Go 1.20, the generator was seeded like Seed(1) at program startup.

I believe it’s important to keep the exercises up-to-date, because learners will most likely use the latest version of the toolchain.

1 Like


Every time this program runs, it will produce the same output:

498081 727887 131847

That’s no longer the case. These are the numbers I got from my testing:

24853 585574 220167
13659 36744 451068
907719 346646 589411

Go version 1.19:

498081 727887 131847
498081 727887 131847
498081 727887 131847

Thanks :slight_smile:

(cc @andrerfcsantos @junedev)

1 Like

There is currently ongoing work on GitHub to update things to Go 1.18 ( Update to Go 1.18 · Issue #2129 · exercism/go (github.com))

I asked why not directly update to Go 1.20. I’m used to use the latest version of Go for years. Which seems to be the preferred and valid way. But with Go 1.18 and Go 1.20 came some significant changes which is good chance you want to use.

With the current test environment, the description here is still valid and not even would work the new way.


Fixed now - Thanks @junedev