Skip to content

Commit

Permalink
Merge pull request #37 from kuzxnia/randfix
Browse files Browse the repository at this point in the history
Randfix
  • Loading branch information
kuzxnia authored Jul 22, 2024
2 parents 7bbfb33 + ae629de commit 78c9619
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/getting_started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loadbot start-agent -f config_file.json

2. Start and watch the workload using the loadbot client:
```bash
loadbot start-agent --progress
loadbot start --progress
Job "My first job" |██████████████████████████████████████████████████████████████████| 30/30S 50RPS 1509REQ
```

Expand Down
8 changes: 7 additions & 1 deletion lbot/schema/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"math/rand"
"strings"
"sync"
"time"

"github.com/go-faker/faker/v4"
Expand Down Expand Up @@ -119,15 +120,20 @@ const (
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)

var src = rand.NewSource(time.Now().UnixNano())
var (
src = rand.NewSource(time.Now().UnixNano())
mu sync.Mutex
)

func randStringBytes(n int) string {
sb := strings.Builder{}
sb.Grow(n)
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
mu.Lock()
cache, remain = src.Int63(), letterIdxMax
mu.Unlock()
}
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
sb.WriteByte(letterBytes[idx])
Expand Down

0 comments on commit 78c9619

Please sign in to comment.