vivekvardha / TaskSchedulingAssignment

Attempted to implement code using channel and go routines which mimics priority based scheduling
0 stars 0 forks source link

Explain: Rand Priority #1

Open hariprasadraja opened 2 years ago

hariprasadraja commented 2 years ago

func RandPriority() int { return rand.Intn(maxPriority-minPriority+1) + minPriority }

what is the point in subtracting and adding again in the random integer generation ?

vivekvardha commented 2 years ago

This function is intended to generate random numbers between 1 to 5 which will be assigned as priority to the task. Hence the name RandPriority of the function. adding value minPriority again because if I dont do it then priority is ranging between 0 to 5.

hariprasadraja commented 2 years ago

what is the role of maxPriority-minPriority+1 ?

vivekvardha commented 2 years ago

maxPrioirty and minPriority are the constants to imply the maximum priority which is 5 and minimum priority which is 1. rand.Intn(maxPriority-minPriority+1) will generate pirority randomly between 1 to 5. I will declare varaibles maxPrioirty and minPriority as constants.

hariprasadraja commented 2 years ago

Instead of rand.Intn(5 - 1 + 1), why can't you have rand.Intn(5)