Skip to content

Commit

Permalink
math/rand/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hueter57 committed Jul 5, 2024
1 parent ef91d11 commit 81b2729
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions testutil/random/ramdom.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package random

import (
"math/rand"
"math/rand/v2"
"testing"

"github.com/stretchr/testify/require"
)

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Expand All @@ -13,28 +11,24 @@ const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
// この関数はmath/randが生成する擬似乱数を使用します
func AlphaNumeric(t *testing.T, n int) string {
t.Helper()
b := make([]byte, n)
// FIXME: https://github.com/traPtitech/Jomon/issues/736
_, err := rand.Read(b) // nolint:staticcheck
require.NoError(t, err)

var result string
for _, v := range b {
result += string(letters[int(v)%len(letters)])
for i := 0; i < n; i++ {
result += string(letters[rand.IntN(len(letters))])
}

return result
}

func Numeric(t *testing.T, max int) int {
t.Helper()
n := rand.Intn(max)
n := rand.IntN(max)
return n
}

func Numeric64(t *testing.T, max int64) int64 {
t.Helper()
n := rand.Int63n(max)
n := rand.Int64N(max)

Check warning on line 31 in testutil/random/ramdom.go

View check run for this annotation

Codecov / codecov/patch

testutil/random/ramdom.go#L31

Added line #L31 was not covered by tests
return n
}

Expand Down

0 comments on commit 81b2729

Please sign in to comment.