From f56fa2be545d736c4063f78e764aca21deb42dac Mon Sep 17 00:00:00 2001 From: Justin Mayhew Date: Wed, 5 Mar 2025 17:41:04 -0400 Subject: [PATCH] Fix usage of rand.IntN While testing out the example I noticed some of the items were never logged because of this off-by-one error. --- README.md | 2 +- examples/basic/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c05d2a0..87cdbe4 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ var wg sync.WaitGroup for i := 0; i < 5; i++ { wg.Add(1) go func() { - ids := []string{batches[rand.IntN(2)][rand.IntN(4)], batches[rand.IntN(2)][rand.IntN(4)]} + ids := []string{batches[rand.IntN(3)][rand.IntN(5)], batches[rand.IntN(3)][rand.IntN(5)]} res, _ := cacheClient.GetOrFetchBatch(context.Background(), ids, keyPrefixFn, fetchFn) log.Printf("got batch: %v\n", res) wg.Done() diff --git a/examples/basic/main.go b/examples/basic/main.go index 69bbfac..a6b9ab2 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -82,7 +82,7 @@ func demonstrateGetOrFetchBatch(cacheClient *sturdyc.Client[int]) { for i := 0; i < 5; i++ { wg.Add(1) go func() { - ids := []string{batches[rand.IntN(2)][rand.IntN(4)], batches[rand.IntN(2)][rand.IntN(4)]} + ids := []string{batches[rand.IntN(3)][rand.IntN(5)], batches[rand.IntN(3)][rand.IntN(5)]} res, _ := cacheClient.GetOrFetchBatch(context.Background(), ids, keyPrefixFn, fetchFn) log.Printf("got batch: %v\n", res) wg.Done()