Skip to content

Update deck.go shuffle function to use math/rand/v2 package (Go 1.22+) #9

@younesious

Description

@younesious

Hello @StephenGrider,

I noticed that the deck.go file in your repository is using the math/rand package for shuffling the deck of cards. With the release of Go 1.22, a new package math/rand/v2 has been introduced, which provides additional features and improvements over the original math/rand package.

I would like to propose an update to the deck.go file to take advantage of the new math/rand/v2 package. Specifically, I suggest removing the following lines:

source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)

and change package into:

import "math/rand/v2"

and changing:

newPosition := r.Intn(len(d) - 1)

to:

newPosition := rand.IntN(len(d) - 1)

This change will not only make use of the newer package but also simplify the code by eliminating the need for creating a new source and random number generator instance.
Please let me know if you have any concerns or if you would like me to make the changes directly through a pull request.
Thank you for accepting my PR
I will send a pull request for this improvement. Please accept it.
Regards,
Younes Mahmoudi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions