Okay, here’s my solution. So, what I’m doing is, I’m using a global variable, which is not a great habit to get into. But, it works in this simple case, to store the index into the list. Basically which server we’re on. And I started at negative 1, so that the first time I incremented it, it increments to 0, so we’ll be at position 0. I’m using the global keyword here, which basically tells Python to, use the global n. The n defined outside this function, instead of making a new variable called n. If I didn’t have this global n, this line would raise an exception saying n is not defined. And then what I do, is I ref, I return the index into the list of servers the correct position. So and what we do is, we say, n modulo length of SERVERS. So length of SERVERS is 4. And if you don’t know how the mod operator works, basically what it does is, it says, give me the remainder of doing the division. So, what this means is, we take n divided by length SERVERS and then we take the remainder of that. That’s what modular does. So if its zero we say 4 goes into 0, 0 times. If n is 1 we say 4 goes into 0, or 4 goes into 1, 0 times with a remainder of 1. And so, so we get an x 1. And so as n increments, you know, when n is 5 we say, you know, link servers 4 goes into 5, one time, with the remainder of one again. So the loop is over. So if we get this a whirl, it would print out something like this. Okay, so if we go ahead and run this, we see our output SERVER 1, 2, 3, 4, 1. so, simple enough, that’s our Round Robin little balancing works. Like I said, you probably want to have to implement this anytime soon. But, there you go.

## Leave a Reply