From fc1144cb1d3c24cf3efbcaea2764027dceae7c58 Mon Sep 17 00:00:00 2001 From: Gator Date: Sun, 1 May 2022 09:15:49 +0200 Subject: [PATCH] simplify random img function --- fs.go | 10 +++------- main.go | 5 ++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/fs.go b/fs.go index f0b4873..dfaf66e 100644 --- a/fs.go +++ b/fs.go @@ -51,13 +51,9 @@ func getImagesList(path string) []string { } // Randomly choose x number of image from a given folder -func getRandomImages(number int) []string { +func getRandomImage() string { rand.Seed(time.Now().UnixNano()) - var images []string dir := getImagesList("/home/gator/Photos/") - for i := 0; i < number; i++ { - index := rand.Intn(len(dir)) - images = append(images, dir[index]) - } - return images + index := rand.Intn(len(dir)) + return dir[index] } diff --git a/main.go b/main.go index a1830a7..7e3a522 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,8 @@ func main() { flag.Parse() // get two random images and load them - imgs := getRandomImages(2) - img1 := loadImage(imgs[0]) - img2 := loadImage(imgs[1]) + img1 := loadImage(getRandomImage()) + img2 := loadImage(getRandomImage()) // pool of workers unionizing, ready to blend a new picture using the power of friendship var pool blendWorkerPool