I have a while loop (below) that uses a runif function to generate random variables that are used in further calculations and conditions before exiting the loop. However, in few cases, this gets stuck in infinite loop as the random number generation does not meet the condition soon.
Is there a way i can include a timeout clause here so that my while loop exits after n seconds?
#lb,ub are user inputs
counter = 1
while(counter == 1){
temp = runif(3,min=0,max=80)
temp2 = 100 - sum(temp)
if (temp2 > ub || temp2 < lb) {
counter = 1
} else counter = 0
}