Skip to content

Commit 3780879

Browse files
committed
datagen: Replace math.Rand with ChaCha8
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
1 parent 48a060d commit 3780879

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This document outlines major changes between releases.
1010

1111
### Changed
1212
- Go 1.21+ is required to build now (#61)
13+
- Replaced `math/rand.Read` with `math/rand/v2.ChaCha8.Read`
1314

1415
## [0.1.2] - 2024-03-11
1516

internal/datagen/generator.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package datagen
22

33
import (
44
"crypto/sha256"
5+
"encoding/binary"
56
"encoding/hex"
6-
"math/rand"
7+
"math/rand/v2"
8+
"time"
79

810
"github.com/dop251/goja"
911
"go.k6.io/k6/js/modules"
@@ -58,8 +60,13 @@ func (g *Generator) nextSlice() []byte {
5860
if g.buf == nil {
5961
// Allocate buffer with extra tail for sliding and populate it with random bytes
6062
g.buf = make([]byte, g.size+TailSize)
63+
64+
var seed [32]byte
65+
binary.LittleEndian.PutUint64(seed[:], uint64(time.Now().UnixNano()))
66+
chaCha8 := rand.NewChaCha8(seed)
67+
6168
//nolint:staticcheck
62-
rand.Read(g.buf) // Per docs, err is always nil here
69+
_, _ = chaCha8.Read(g.buf) // Per docs, err is always nil here
6370
}
6471

6572
result := g.buf[g.offset : g.offset+g.size]

0 commit comments

Comments
 (0)