This should be a simple question, but I haven\'t been able to find a way to make it work.
Essentially, I have a silly localhost page that I use in my webdevelopment.
You need a difference in brightness for text to be readable, as color vision itself has too low resolution.
So as an algorithm I'd suggest the following:
Pick a random background color.
Then decide whether it is a light or a dark color. For example you could check whether the average of the three primary colors is greater or equal 128.
For a light color use black text, for a dark one white text.