From 2b50356acf78ddcc3ba5cd0a8eedfd37a1c8e87c Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Wed, 18 Aug 2021 18:24:14 +0300 Subject: [PATCH] make RNG inclusive on both ends --- routes/routes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/routes.go b/routes/routes.go index 73cea43..4208670 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -39,8 +39,8 @@ func RandomHandler(w http.ResponseWriter, req *http.Request) { min := 1 // seed the default source using the current time in unix nanosecond format rand.Seed(time.Now().UnixNano()) - // generate random number between min and `max` - num := rand.Intn(int(max)-min) + min + // generate random number between min and max [min, max] + num := rand.Intn(int(max+1)-min) + min // find the random kot document and store it in the `kot` variable err = db.Kots.FindOne(db.Ctx, bson.M{"id": num}).Decode(&kot)