Fix: instead of 30 use random number between 5 and 50
This commit is contained in:
parent
13091c74a8
commit
a54ddfe5f3
1 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue