mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-08-01 22:34:02 +00:00
Migrate to rand/v2
This commit is contained in:
parent
a013192bf8
commit
8d79680b81
7 changed files with 21 additions and 24 deletions
|
|
@ -3,7 +3,7 @@ package com
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -90,12 +90,11 @@ func testWebsocket(t *testing.T) {
|
|||
for _, call := range calls {
|
||||
call := call
|
||||
if call.concurrent {
|
||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := 0; i < n; i++ {
|
||||
packet := call.packet
|
||||
go func() {
|
||||
defer wait.Done()
|
||||
time.Sleep(time.Duration(rand.Intn(200-100)+100) * time.Millisecond)
|
||||
time.Sleep(time.Duration(rand.IntN(200-100)+100) * time.Millisecond)
|
||||
vv, err := client.rpc.Call(client.sock.conn, &packet)
|
||||
err = checkCall(vv, err, call.value)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"image/png"
|
||||
"io"
|
||||
"math"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
|
@ -169,7 +169,7 @@ func BenchmarkYuv(b *testing.B) {
|
|||
{w: 1920, h: 1080},
|
||||
{w: 320, h: 240},
|
||||
}
|
||||
r1 := rand.New(rand.NewSource(int64(1))).Float32()
|
||||
r1 := rand.Float32()
|
||||
|
||||
for _, test := range tests {
|
||||
w, h := test.w, test.h
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package games
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -59,5 +59,5 @@ func ExtractGame(roomID string) string {
|
|||
// RoomID contains random number + gameName
|
||||
// Next time when we only get roomID, we can launch game based on gameName
|
||||
func GenerateRoomID(title string) string {
|
||||
return strconv.FormatInt(rand.Int63(), 16) + separator + title
|
||||
return strconv.FormatInt(rand.Int64(), 16) + separator + title
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
|
@ -333,7 +333,7 @@ func TestConcurrentInput(t *testing.T) {
|
|||
wg.Add(2 * events)
|
||||
|
||||
for i := 0; i < events; i++ {
|
||||
player := rand.Intn(maxPort)
|
||||
player := rand.IntN(maxPort)
|
||||
go func() { state.setInput(player, []byte{0, 1}); wg.Done() }()
|
||||
go func() { state.isKeyPressed(uint(player), 100); wg.Done() }()
|
||||
}
|
||||
|
|
@ -362,4 +362,4 @@ func expand(p ...string) string {
|
|||
func hash(bytes []byte) string { return fmt.Sprintf("%x", md5.Sum(bytes)) }
|
||||
|
||||
// lucky returns random boolean.
|
||||
func lucky() bool { return rand.Intn(2) == 1 }
|
||||
func lucky() bool { return rand.IntN(2) == 1 }
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package media
|
|||
|
||||
import (
|
||||
"image"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
|
@ -25,8 +25,8 @@ func TestEncoders(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
a := genTestImage(test.w, test.h, rand.New(rand.NewSource(int64(1))).Float32())
|
||||
b := genTestImage(test.w, test.h, rand.New(rand.NewSource(int64(2))).Float32())
|
||||
a := genTestImage(test.w, test.h, rand.Float32())
|
||||
b := genTestImage(test.w, test.h, rand.Float32())
|
||||
for i := 0; i < test.n; i++ {
|
||||
run(test.w, test.h, test.codec, test.frames, a, b, t)
|
||||
}
|
||||
|
|
@ -71,10 +71,10 @@ func run(w, h int, cod encoder.VideoCodec, count int, a *image.RGBA, b *image.RG
|
|||
defer ve.Stop()
|
||||
|
||||
if a == nil {
|
||||
a = genTestImage(w, h, rand.New(rand.NewSource(int64(1))).Float32())
|
||||
a = genTestImage(w, h, rand.Float32())
|
||||
}
|
||||
if b == nil {
|
||||
b = genTestImage(w, h, rand.New(rand.NewSource(int64(2))).Float32())
|
||||
b = genTestImage(w, h, rand.Float32())
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
|
|
@ -146,7 +146,7 @@ func BenchmarkResampler(b *testing.B) {
|
|||
func gen(l int) []int16 {
|
||||
nums := make([]int16, l)
|
||||
for i := range nums {
|
||||
nums[i] = int16(rand.Intn(10))
|
||||
nums[i] = int16(rand.IntN(10))
|
||||
}
|
||||
return nums
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package recorder
|
|||
|
||||
import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
|
@ -204,7 +204,7 @@ func random(num string) string {
|
|||
}
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
|
||||
b[i] = letterBytes[rand.Int64()%int64(len(letterBytes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
"log"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -147,13 +147,11 @@ func genFrame(w, h int) Frame {
|
|||
}
|
||||
}
|
||||
|
||||
var rnd = rand.New(rand.NewSource(time.Now().Unix()))
|
||||
|
||||
func randomColor() color.RGBA {
|
||||
return color.RGBA{
|
||||
R: uint8(rnd.Intn(256)),
|
||||
G: uint8(rnd.Intn(256)),
|
||||
B: uint8(rnd.Intn(256)),
|
||||
R: uint8(rand.IntN(256)),
|
||||
G: uint8(rand.IntN(256)),
|
||||
B: uint8(rand.IntN(256)),
|
||||
A: 255,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue