all: use math/rand/v2

This commit is contained in:
Hajime Hoshi 2024-09-12 01:03:53 +09:00
parent a4bfa6cb15
commit 4bccf9d009
24 changed files with 67 additions and 140 deletions

View File

@ -17,7 +17,7 @@ package convert_test
import ( import (
"bytes" "bytes"
"io" "io"
"math/rand" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22. "math/rand/v2"
"testing" "testing"
"unsafe" "unsafe"
@ -27,7 +27,7 @@ import (
func randInt16s(n int) []int16 { func randInt16s(n int) []int16 {
r := make([]int16, n) r := make([]int16, n)
for i := range r { for i := range r {
r[i] = int16(rand.Intn(1<<16) - (1 << 15)) r[i] = int16(rand.IntN(1<<16) - (1 << 15))
} }
return r return r
} }

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"math/rand" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22. "math/rand/v2"
"testing" "testing"
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert" "github.com/hajimehoshi/ebiten/v2/audio/internal/convert"

View File

@ -17,8 +17,8 @@ package convert_test
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io" // TODO: Use math/rand/v2 when the minimum supported version becomes Go 1.22. "io"
"math/rand" "math/rand/v2"
"testing" "testing"
"github.com/hajimehoshi/ebiten/v2/audio/internal/convert" "github.com/hajimehoshi/ebiten/v2/audio/internal/convert"
@ -101,7 +101,7 @@ func TestStereoI16(t *testing.T) {
func randBytes(n int) []byte { func randBytes(n int) []byte {
r := make([]byte, n) r := make([]byte, n)
for i := range r { for i := range r {
r[i] = byte(rand.Intn(256)) r[i] = byte(rand.IntN(256))
} }
return r return r
} }

View File

@ -15,16 +15,9 @@
package twenty48 package twenty48
import ( import (
"math/rand"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
const ( const (
ScreenWidth = 420 ScreenWidth = 420
ScreenHeight = 600 ScreenHeight = 600

View File

@ -19,7 +19,7 @@ import (
"errors" "errors"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"sort" "sort"
"strconv" "strconv"
@ -261,9 +261,9 @@ func addRandomTile(tiles map[*Tile]struct{}, size int) error {
if len(availableCells) == 0 { if len(availableCells) == 0 {
return errors.New("twenty48: there is no space to add a new tile") return errors.New("twenty48: there is no space to add a new tile")
} }
c := availableCells[rand.Intn(len(availableCells))] c := availableCells[rand.IntN(len(availableCells))]
v := 2 v := 2
if rand.Intn(10) == 0 { if rand.IntN(10) == 0 {
v = 4 v = 4
} }
x := c % size x := c % size

View File

@ -20,9 +20,8 @@ import (
"image/color" "image/color"
_ "image/jpeg" _ "image/jpeg"
_ "image/png" _ "image/png"
"math/rand" "math/rand/v2"
"strconv" "strconv"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/colorm" "github.com/hajimehoshi/ebiten/v2/colorm"
@ -139,10 +138,6 @@ type GameScene struct {
gameover bool gameover bool
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
func NewGameScene() *GameScene { func NewGameScene() *GameScene {
return &GameScene{ return &GameScene{
field: &Field{}, field: &Field{},
@ -194,7 +189,7 @@ const (
func (s *GameScene) choosePiece() *Piece { func (s *GameScene) choosePiece() *Piece {
num := int(BlockTypeMax) num := int(BlockTypeMax)
blockType := BlockType(rand.Intn(num) + 1) blockType := BlockType(rand.IntN(num) + 1)
return Pieces[blockType] return Pieces[blockType]
} }

View File

@ -18,7 +18,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"

View File

@ -17,8 +17,7 @@ package main
import ( import (
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
) )
@ -102,7 +101,7 @@ func (g *Game) updateFireIntensityPerPixel(currentPixelIndex int) {
return return
} }
d := rand.Intn(3) d := rand.IntN(3)
newI := int(g.indices[below]) - d newI := int(g.indices[below]) - d
if newI < 0 { if newI < 0 {
newI = 0 newI = 0
@ -139,8 +138,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
rand.Seed(time.Now().UnixNano())
ebiten.SetWindowSize(screenWidth*6, screenHeight*6) ebiten.SetWindowSize(screenWidth*6, screenHeight*6)
ebiten.SetWindowTitle("Doom Fire (Ebitengine Demo)") ebiten.SetWindowTitle("Doom Fire (Ebitengine Demo)")
if err := ebiten.RunGame(NewGame()); err != nil { if err := ebiten.RunGame(NewGame()); err != nil {

View File

@ -20,8 +20,7 @@ import (
"image/color" "image/color"
_ "image/png" _ "image/png"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -29,10 +28,6 @@ import (
"github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/hajimehoshi/ebiten/v2/inpututil"
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
const ( const (
screenWidth = 640 screenWidth = 640
screenHeight = 480 screenHeight = 480
@ -196,8 +191,8 @@ func NewGame() *Game {
s := &Sprite{ s := &Sprite{
image: ebitenImage, image: ebitenImage,
alphaImage: ebitenAlphaImage, alphaImage: ebitenAlphaImage,
x: rand.Intn(screenWidth - w), x: rand.IntN(screenWidth - w),
y: rand.Intn(screenHeight - h), y: rand.IntN(screenHeight - h),
} }
sprites = append(sprites, s) sprites = append(sprites, s)
} }

View File

@ -24,8 +24,7 @@ import (
_ "image/png" _ "image/png"
"log" "log"
"math" "math"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/audio" "github.com/hajimehoshi/ebiten/v2/audio"
@ -44,10 +43,6 @@ var flagCRT = flag.Bool("crt", false, "enable the CRT effect")
//go:embed crt.go //go:embed crt.go
var crtGo []byte var crtGo []byte
func init() {
rand.Seed(time.Now().UnixNano())
}
func floorDiv(x, y int) int { func floorDiv(x, y int) int {
d := x / y d := x / y
if d*y == x || x >= 0 { if d*y == x || x >= 0 {
@ -150,7 +145,7 @@ func (g *Game) init() {
g.cameraY = 0 g.cameraY = 0
g.pipeTileYs = make([]int, 256) g.pipeTileYs = make([]int, 256)
for i := range g.pipeTileYs { for i := range g.pipeTileYs {
g.pipeTileYs[i] = rand.Intn(6) + 2 g.pipeTileYs[i] = rand.IntN(6) + 2
} }
if g.audioContext == nil { if g.audioContext == nil {

View File

@ -19,8 +19,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts" "github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
@ -94,10 +93,6 @@ func init() {
mplusFaceSource = s mplusFaceSource = s
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
type Game struct { type Game struct {
counter int counter int
kanjiText string kanjiText string
@ -110,14 +105,14 @@ func (g *Game) Update() error {
g.kanjiText = "" g.kanjiText = ""
for j := 0; j < 6; j++ { for j := 0; j < 6; j++ {
for i := 0; i < 12; i++ { for i := 0; i < 12; i++ {
g.kanjiText += string(jaKanjis[rand.Intn(len(jaKanjis))]) g.kanjiText += string(jaKanjis[rand.IntN(len(jaKanjis))])
} }
g.kanjiText += "\n" g.kanjiText += "\n"
} }
g.kanjiTextColor.R = 0x80 + uint8(rand.Intn(0x7f)) g.kanjiTextColor.R = 0x80 + uint8(rand.IntN(0x7f))
g.kanjiTextColor.G = 0x80 + uint8(rand.Intn(0x7f)) g.kanjiTextColor.G = 0x80 + uint8(rand.IntN(0x7f))
g.kanjiTextColor.B = 0x80 + uint8(rand.Intn(0x7f)) g.kanjiTextColor.B = 0x80 + uint8(rand.IntN(0x7f))
g.kanjiTextColor.A = 0xff g.kanjiTextColor.A = 0xff
} }
g.counter++ g.counter++

View File

@ -16,8 +16,7 @@ package main
import ( import (
"fmt" "fmt"
"math/rand" "math/rand/v2"
"time"
) )
// Level represents a Game level. // Level represents a Game level.
@ -56,9 +55,6 @@ func NewLevel() (*Level, error) {
return nil, fmt.Errorf("failed to load embedded spritesheet: %s", err) return nil, fmt.Errorf("failed to load embedded spritesheet: %s", err)
} }
// Generate a unique permutation each time.
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
// Fill each tile with one or more sprites randomly. // Fill each tile with one or more sprites randomly.
l.tiles = make([][]*Tile, l.h) l.tiles = make([][]*Tile, l.h)
for y := 0; y < l.h; y++ { for y := 0; y < l.h; y++ {
@ -66,7 +62,7 @@ func NewLevel() (*Level, error) {
for x := 0; x < l.w; x++ { for x := 0; x < l.w; x++ {
t := &Tile{} t := &Tile{}
isBorderSpace := x == 0 || y == 0 || x == l.w-1 || y == l.h-1 isBorderSpace := x == 0 || y == 0 || x == l.w-1 || y == l.h-1
val := r.Intn(1000) val := rand.IntN(1000)
switch { switch {
case isBorderSpace || val < 275: case isBorderSpace || val < 275:
t.AddSprite(ss.Wall) t.AddSprite(ss.Wall)

View File

@ -8,16 +8,11 @@ package main
import ( import (
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
// World represents the game state. // World represents the game state.
type World struct { type World struct {
area []bool area []bool
@ -39,8 +34,8 @@ func NewWorld(width, height int, maxInitLiveCells int) *World {
// init inits world with a random state. // init inits world with a random state.
func (w *World) init(maxLiveCells int) { func (w *World) init(maxLiveCells int) {
for i := 0; i < maxLiveCells; i++ { for i := 0; i < maxLiveCells; i++ {
x := rand.Intn(w.width) x := rand.IntN(w.width)
y := rand.Intn(w.height) y := rand.IntN(w.height)
w.area[y*w.width+x] = true w.area[y*w.width+x] = true
} }
} }

View File

@ -21,8 +21,7 @@ import (
"image" "image"
_ "image/png" _ "image/png"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
rmascot "github.com/hajimehoshi/ebiten/v2/examples/resources/images/mascot" rmascot "github.com/hajimehoshi/ebiten/v2/examples/resources/images/mascot"
@ -60,10 +59,6 @@ func init() {
gopher3 = ebiten.NewImageFromImage(img3) gopher3 = ebiten.NewImageFromImage(img3)
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
type mascot struct { type mascot struct {
x16 int x16 int
y16 int y16 int
@ -105,8 +100,8 @@ func (m *mascot) Update() error {
} }
// If the mascto is on the ground, cause an action in random. // If the mascto is on the ground, cause an action in random.
if rand.Intn(60) == 0 && m.y16 == 0 { if rand.IntN(60) == 0 && m.y16 == 0 {
switch rand.Intn(2) { switch rand.IntN(2) {
case 0: case 0:
// Jump. // Jump.
m.vy16 = -240 m.vy16 = -240

View File

@ -23,18 +23,13 @@ import (
_ "image/png" _ "image/png"
"log" "log"
"math" "math"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images" "github.com/hajimehoshi/ebiten/v2/examples/resources/images"
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
const ( const (
screenWidth = 640 screenWidth = 640
screenHeight = 480 screenHeight = 480
@ -110,7 +105,7 @@ func (s *sprite) draw(screen *ebiten.Image) {
} }
func newSprite(img *ebiten.Image) *sprite { func newSprite(img *ebiten.Image) *sprite {
c := rand.Intn(50) + 300 c := rand.IntN(50) + 300
dir := rand.Float64() * 2 * math.Pi dir := rand.Float64() * 2 * math.Pi
a := rand.Float64() * 2 * math.Pi a := rand.Float64() * 2 * math.Pi
s := rand.Float64()*0.1 + 0.4 s := rand.Float64()*0.1 + 0.4
@ -136,7 +131,7 @@ func (g *Game) Update() error {
g.sprites = list.New() g.sprites = list.New()
} }
if g.sprites.Len() < 500 && rand.Intn(4) < 3 { if g.sprites.Len() < 500 && rand.IntN(4) < 3 {
// Emit // Emit
g.sprites.PushBack(newSprite(smokeImage)) g.sprites.PushBack(newSprite(smokeImage))
} }

View File

@ -18,8 +18,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -30,10 +29,6 @@ const (
screenHeight = 240 screenHeight = 240
) )
func init() {
rand.Seed(time.Now().UnixNano())
}
type Game struct { type Game struct {
offscreen *ebiten.Image offscreen *ebiten.Image
} }
@ -46,12 +41,12 @@ func NewGame() *Game {
func (g *Game) Update() error { func (g *Game) Update() error {
s := g.offscreen.Bounds().Size() s := g.offscreen.Bounds().Size()
x := rand.Intn(s.X) x := rand.IntN(s.X)
y := rand.Intn(s.Y) y := rand.IntN(s.Y)
c := color.RGBA{ c := color.RGBA{
byte(rand.Intn(256)), byte(rand.IntN(256)),
byte(rand.Intn(256)), byte(rand.IntN(256)),
byte(rand.Intn(256)), byte(rand.IntN(256)),
byte(0xff), byte(0xff),
} }
g.offscreen.Set(x, y, c) g.offscreen.Set(x, y, c)

View File

@ -18,8 +18,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -59,10 +58,6 @@ type Game struct {
level int level int
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
func (g *Game) collidesWithApple() bool { func (g *Game) collidesWithApple() bool {
return g.snakeBody[0].X == g.apple.X && return g.snakeBody[0].X == g.apple.X &&
g.snakeBody[0].Y == g.apple.Y g.snakeBody[0].Y == g.apple.Y
@ -130,8 +125,8 @@ func (g *Game) Update() error {
} }
if g.collidesWithApple() { if g.collidesWithApple() {
g.apple.X = rand.Intn(xGridCountInScreen - 1) g.apple.X = rand.IntN(xGridCountInScreen - 1)
g.apple.Y = rand.Intn(yGridCountInScreen - 1) g.apple.Y = rand.IntN(yGridCountInScreen - 1)
g.snakeBody = append(g.snakeBody, Position{ g.snakeBody = append(g.snakeBody, Position{
X: g.snakeBody[len(g.snakeBody)-1].X, X: g.snakeBody[len(g.snakeBody)-1].X,
Y: g.snakeBody[len(g.snakeBody)-1].Y, Y: g.snakeBody[len(g.snakeBody)-1].Y,

View File

@ -21,7 +21,7 @@ import (
_ "image/png" _ "image/png"
"log" "log"
"math" "math"
"math/rand" "math/rand/v2"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -119,9 +119,9 @@ func (g *Game) init() {
g.sprites.num = 500 g.sprites.num = 500
for i := range g.sprites.sprites { for i := range g.sprites.sprites {
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy() w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h) x, y := rand.IntN(screenWidth-w), rand.IntN(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1 vx, vy := 2*rand.IntN(2)-1, 2*rand.IntN(2)-1
a := rand.Intn(maxAngle) a := rand.IntN(maxAngle)
g.sprites.sprites[i] = &Sprite{ g.sprites.sprites[i] = &Sprite{
imageWidth: w, imageWidth: w,
imageHeight: h, imageHeight: h,

View File

@ -21,7 +21,7 @@ import (
_ "image/png" _ "image/png"
"log" "log"
"math" "math"
"math/rand" "math/rand/v2"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -117,9 +117,9 @@ func (g *Game) init() {
g.sprites.num = 500 g.sprites.num = 500
for i := range g.sprites.sprites { for i := range g.sprites.sprites {
w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy() w, h := ebitenImage.Bounds().Dx(), ebitenImage.Bounds().Dy()
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h) x, y := rand.IntN(screenWidth-w), rand.IntN(screenHeight-h)
vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1 vx, vy := 2*rand.IntN(2)-1, 2*rand.IntN(2)-1
a := rand.Intn(maxAngle) a := rand.IntN(maxAngle)
g.sprites.sprites[i] = &Sprite{ g.sprites.sprites[i] = &Sprite{
imageWidth: w, imageWidth: w,
imageHeight: h, imageHeight: h,

View File

@ -20,8 +20,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -127,8 +126,8 @@ type squiral struct {
func (s *squiral) spawn(game *Game) { func (s *squiral) spawn(game *Game) {
s.dead = false s.dead = false
rx := rand.Intn(width-4) + 2 rx := rand.IntN(width-4) + 2
ry := rand.Intn(height-4) + 2 ry := rand.IntN(height-4) + 2
for dx := -2; dx <= 2; dx++ { for dx := -2; dx <= 2; dx++ {
for dy := -2; dy <= 2; dy++ { for dy := -2; dy <= 2; dy++ {
@ -140,15 +139,15 @@ func (s *squiral) spawn(game *Game) {
} }
} }
s.speed = rand.Intn(5) + 1 s.speed = rand.IntN(5) + 1
s.pos.x = rx s.pos.x = rx
s.pos.y = ry s.pos.y = ry
s.dir = rand.Intn(4) s.dir = rand.IntN(4)
game.colorCycle = (game.colorCycle + 1) % len(palettes[game.selectedPalette].colors) game.colorCycle = (game.colorCycle + 1) % len(palettes[game.selectedPalette].colors)
s.col = palettes[game.selectedPalette].colors[game.colorCycle] s.col = palettes[game.selectedPalette].colors[game.colorCycle]
s.rot = rand.Intn(2) s.rot = rand.IntN(2)
} }
func (s *squiral) step(game *Game) { func (s *squiral) step(game *Game) {
@ -157,7 +156,7 @@ func (s *squiral) step(game *Game) {
} }
x, y := s.pos.x, s.pos.y // shorthands x, y := s.pos.x, s.pos.y // shorthands
change := rand.Intn(1000) change := rand.IntN(1000)
if change < 2 { if change < 2 {
// On 0.2% of iterations, switch rotation direction. // On 0.2% of iterations, switch rotation direction.
s.rot = (s.rot + 1) % 2 s.rot = (s.rot + 1) % 2
@ -267,10 +266,6 @@ func (a *automaton) step(game *Game) {
} }
} }
func init() {
rand.Seed(time.Now().UnixNano())
}
type Game struct { type Game struct {
selectedPalette int selectedPalette int
colorCycle int colorCycle int

View File

@ -17,8 +17,7 @@ package main
import ( import (
"image/color" "image/color"
"log" "log"
"math/rand" "math/rand/v2"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/vector" "github.com/hajimehoshi/ebiten/v2/vector"
@ -97,7 +96,6 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
} }
func main() { func main() {
rand.Seed(time.Now().UnixNano())
ebiten.SetWindowSize(screenWidth, screenHeight) ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("Stars (Ebitengine Demo)") ebiten.SetWindowTitle("Stars (Ebitengine Demo)")
if err := ebiten.RunGame(NewGame()); err != nil { if err := ebiten.RunGame(NewGame()); err != nil {

View File

@ -22,12 +22,11 @@ import (
_ "image/jpeg" _ "image/jpeg"
"log" "log"
"math" "math"
"math/rand" "math/rand/v2"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil" "github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -55,7 +54,6 @@ var (
func init() { func init() {
flag.Parse() flag.Parse()
rand.Seed(time.Now().UnixNano())
} }
const ( const (
@ -71,9 +69,9 @@ var (
func createRandomIconImage() image.Image { func createRandomIconImage() image.Image {
const size = 32 const size = 32
rf := float64(rand.Intn(0x100)) rf := float64(rand.IntN(0x100))
gf := float64(rand.Intn(0x100)) gf := float64(rand.IntN(0x100))
bf := float64(rand.Intn(0x100)) bf := float64(rand.IntN(0x100))
img := ebiten.NewImage(size, size) img := ebiten.NewImage(size, size)
pix := make([]byte, 4*size*size) pix := make([]byte, 4*size*size)
for j := 0; j < size; j++ { for j := 0; j < size; j++ {

View File

@ -22,10 +22,9 @@ import (
"image/draw" "image/draw"
_ "image/png" _ "image/png"
"math" "math"
"math/rand" "math/rand/v2"
"runtime" "runtime"
"testing" "testing"
"time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/images" "github.com/hajimehoshi/ebiten/v2/examples/resources/images"
@ -37,10 +36,6 @@ import (
// maxImageSize is a maximum image size that should work in almost every environment. // maxImageSize is a maximum image size that should work in almost every environment.
const maxImageSize = 4096 - 2 const maxImageSize = 4096 - 2
func init() {
rand.Seed(time.Now().UnixNano())
}
func skipTooSlowTests(t *testing.T) bool { func skipTooSlowTests(t *testing.T) bool {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode") t.Skip("skipping test in short mode")
@ -4272,7 +4267,7 @@ func TestImageAntiAlias(t *testing.T) {
ebiten.BlendXor, ebiten.BlendXor,
ebiten.BlendLighter, ebiten.BlendLighter,
} { } {
rnd := rand.New(rand.NewSource(0)) rnd := rand.New(rand.NewPCG(0, 0))
max := func(x, y, z byte) byte { max := func(x, y, z byte) byte {
if x >= y && x >= z { if x >= y && x >= z {
return x return x

View File

@ -16,7 +16,7 @@ package affine_test
import ( import (
"math" "math"
"math/rand" "math/rand/v2"
"testing" "testing"
"github.com/hajimehoshi/ebiten/v2/internal/affine" "github.com/hajimehoshi/ebiten/v2/internal/affine"