Board index » cppbuilder » Queues & Random Numbers
Andrew Edwards
CBuilder Developer |
Queues & Random Numbers2003-06-29 11:57:21 PM cppbuilder98 I'm not sure what exactly I'm doing wrong here, please advise. I'm trying to randomly select numbers from the interval [0, 3] If the number is either 0 or 3, I will ignore it, otherwise I will enqueue that many customers at the time of arrival. For every minute that passes I will take one serve one customer, thereby removing them from the queue. The problem I'm facing with the current implementation is that the program does not accurately track the customers upon arrival. Additionally, it crashes for any for intervals less than four minutes (simLength = 4). Thanks in Advance, Andrew ======================================== for ( minute = 0 ; minute < simLength ; minute++ ) { // Dequeue the first customer in line (if any). Increment // totalServed, add the time that this customer waited to // totalWait, and update maxWait if this customer waited // longer than any previous customer. if (!custQ.isEmpty()) { timeArrived = custQ.dequeue(); waitTime = minute - timeArrived; totalServed++; totalWait += waitTime; if (waitTime>maxWait) maxWait = waitTime; } // Determine the number of new customers and add them to // the line. const int N = 4; srand((unsigned)time(NULL)+minute); numArrivals = (rand() % N); switch(numArrivals) { case 0: case 3: break; case 1: custQ.enqueue(minute); break; case 2: custQ.enqueue(minute); custQ.enqueue(minute); break; } } |