Skip to content

Commit

Permalink
Merge pull request #861 from isucon/feature-refactor-use-rand-v2
Browse files Browse the repository at this point in the history
replace math/rand with math/rand/v2
  • Loading branch information
catatsuy authored Aug 25, 2024
2 parents c263c51 + 8bdbb00 commit f0776fc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions bench/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"io"
"log"
"math/rand"
"math/rand/v2"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -361,7 +361,7 @@ func GetRandomActiveSellerIDs(num int) []int64 {
num = len
}
newIDs := make([]int64, 0, num)
s := rand.Intn(len)
s := rand.IntN(len)
for i := 0; i < num; i++ {
newIDs = append(newIDs, activeSellerIDs[s])
s++
Expand All @@ -385,7 +385,7 @@ func GetRandomBuyerIDs(num int) []int64 {
num = len
}
newIDs := make([]int64, 0, num)
s := rand.Intn(len)
s := rand.IntN(len)
for i := 0; i < num; i++ {
newIDs = append(newIDs, buyerIDs[s])
s++
Expand Down Expand Up @@ -509,20 +509,20 @@ func GetRandomImageFileName() string {
}

func GetRandomRootCategory() AppCategory {
return rootCategories[rand.Intn(len(rootCategories))]
return rootCategories[rand.IntN(len(rootCategories))]
}

func GetRootCategories() []AppCategory {
return rootCategories
}

func GetRandomChildCategory() AppCategory {
return childCategories[rand.Intn(len(childCategories))]
return childCategories[rand.IntN(len(childCategories))]
}

func GetRandomChildCategoryByParentID(targetCategory int) AppCategory {
categories := rootCategoriesMap[targetCategory]
return categories[rand.Intn(len(categories))]
return categories[rand.IntN(len(categories))]
}

func GetCategory(categoryID int) (AppCategory, bool) {
Expand All @@ -545,7 +545,7 @@ func GenText(length int, isLine bool) string {
texts := make([]string, 0, length)

for i := 0; i < length; i++ {
t := keywords[rand.Intn(len(keywords))]
t := keywords[rand.IntN(len(keywords))]

if t == "#" {
if isLine {
Expand Down
4 changes: 2 additions & 2 deletions bench/scenario/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scenario
import (
"context"
"log"
"math/rand"
"math/rand/v2"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -158,7 +158,7 @@ func popularListing(ctx context.Context, num int, price int) (isIncrease bool) {
// 成功するかどうか分からなくしておけば、何人かはロックを取っておく必要が出る
cardNumber := ""
failed := false
if rand.Intn(10) == 0 {
if rand.IntN(10) == 0 {
failed = true
cardNumber = FailedCardNumber
} else {
Expand Down
2 changes: 1 addition & 1 deletion bench/scenario/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scenario
import (
"context"
"fmt"
"math/rand"
"math/rand/v2"
"sync"

"github.com/isucon/isucon9-qualify/bench/asset"
Expand Down
4 changes: 2 additions & 2 deletions bench/server/shipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"hash"
"log"
"math/rand"
"math/rand/v2"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -84,7 +84,7 @@ func (c *shipmentStore) Set(value shipment) string {

c.Lock()
for ok := true; ok; {
key = fmt.Sprintf("%010d", rand.Intn(10000000000))
key = fmt.Sprintf("%010d", rand.IntN(10000000000))
_, ok = c.items[key]
}
c.items[key] = value
Expand Down

0 comments on commit f0776fc

Please sign in to comment.