diff --git a/multi-threading/fibonacci-multi-threaded.go b/multi-threading/fibonacci-multi-threaded.go index c4432f9..c3b86b4 100644 --- a/multi-threading/fibonacci-multi-threaded.go +++ b/multi-threading/fibonacci-multi-threaded.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math/rand" "sync" "time" ) @@ -35,6 +36,12 @@ func worker(id int, tasks <-chan Task, wg *sync.WaitGroup) { func main() { const numWorkers = 3 const numTasks = 10 + // Max and Min Fibonacci numbers + const maxFib = 50 + const minFib = 5 + + // Seed the random number generator + rand.Seed(time.Now().UnixNano()) // Create a channel to send tasks to workers tasks := make(chan Task, numTasks) @@ -54,6 +61,8 @@ func main() { tasks <- Task{id: i, n: 30} // n=30 is computationally intensive for Fibonacci } + n := rand.Intn(maxFib - minFib) // Random number between minFib and maxFib + tasks <- Task{id: i, n: n} // Close the task channel to signal no more tasks close(tasks)