Skip to content

Commit

Permalink
Migrate to math/rand/v2 (and by extension Go 1.22)
Browse files Browse the repository at this point in the history
If this thing can't adopt a new and improved version of the rand package
less than 12 hours after its first stable release, what is it even for?

It's the randomizer. It has one job. And it deserves the best tools the
Go standard library has to offer.
  • Loading branch information
ahamlinman committed Feb 7, 2024
1 parent 22383e5 commit 4bb8043
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax = docker.io/docker/dockerfile:1.6

ARG ALPINE_BASE=docker.io/library/alpine:3.18
ARG GOLANG_BASE=docker.io/library/golang:1.21-alpine3.18
ARG ALPINE_BASE=docker.io/library/alpine:3.19
ARG GOLANG_BASE=docker.io/library/golang:1.22-alpine3.19


FROM --platform=$BUILDPLATFORM $GOLANG_BASE AS build
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.alexhamlin.co/randomizer

go 1.21
go 1.22

require (
cloud.google.com/go/firestore v1.14.0
Expand Down
6 changes: 2 additions & 4 deletions internal/randomizer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package randomizer

import (
"context"
"math/rand"
"time"
"math/rand/v2"
)

// Store represents an object that provides persistence for "groups" of
Expand Down Expand Up @@ -44,8 +43,7 @@ func NewApp(name string, store Store) App {
}

func shuffle(options []string) {
source := rand.NewSource(time.Now().UnixNano())
rand.New(source).Shuffle(len(options), func(i, j int) {
rand.Shuffle(len(options), func(i, j int) {
options[i], options[j] = options[j], options[i]
})
}
Expand Down

0 comments on commit 4bb8043

Please sign in to comment.