Can you use something like HSL? I seem to recall that being good to generate a random set of colors. You might start with a hue of zero and increase by certain increments, then increase or decrease saturation or luminance when you get back to 360
IIRC HSL can be converted to RGB. It does need to be RGB eventually.
If you want it to depend on the particular teacher you could hash their name mod 0xFFFFFF and use that as the RGB. Then you can add new teachers but old ones still get the same colour. There's always the possibility of a collision though.