forked from TrueCloudLab/xk6-frostfs
[TrueCloudLab#22] datagen: Use local randomness source
`math/rand.Read` is deprecated. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
e96d83549b
commit
b1f7b29848
1 changed files with 3 additions and 5 deletions
|
@ -22,6 +22,7 @@ type (
|
|||
Generator struct {
|
||||
vu modules.VU
|
||||
size int
|
||||
rand *rand.Rand
|
||||
buf []byte
|
||||
offset int
|
||||
}
|
||||
|
@ -35,10 +36,6 @@ type (
|
|||
// TailSize specifies number of extra random bytes in the buffer tail.
|
||||
const TailSize = 1024
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func NewGenerator(vu modules.VU, size int) Generator {
|
||||
if size <= 0 {
|
||||
panic("size should be positive")
|
||||
|
@ -46,6 +43,7 @@ func NewGenerator(vu modules.VU, size int) Generator {
|
|||
return Generator{
|
||||
vu: vu,
|
||||
size: size,
|
||||
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||
buf: make([]byte, size+TailSize),
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +64,7 @@ func (g *Generator) GenPayload(calcHash bool) GenPayloadResponse {
|
|||
func (g *Generator) nextSlice() []byte {
|
||||
if g.offset >= TailSize {
|
||||
g.offset = 0
|
||||
rand.Read(g.buf) // Per docs, err is always nil here
|
||||
g.rand.Read(g.buf) // Per docs, err is always nil here
|
||||
}
|
||||
|
||||
result := g.buf[g.offset : g.offset+g.size]
|
||||
|
|
Loading…
Reference in a new issue