1
0
Fork 0

Fix: instead of 30 use random number between 5 and 50

This commit is contained in:
Aroy-Art 2024-07-18 23:18:46 +02:00
parent 13091c74a8
commit a54ddfe5f3
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -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)