"Dark" is a relative term. Between #FFFFFF
, #FFFFAA
and #FFFFFE
, the second one is "dark". But in general parlance, none of them would be considered dark colors. There are also different concepts that could be translated as darkness/brightness, such as luminance, value, photometric luminosity, etc.
So you need to first define what type of darkness you're interested in and also a threshold for the value you're measuring.
This question on the brightness of RGB values contains algorithms for various brightness calculations. Perceptual luminance is probably the most appropriate formula for this particular question (though there are probably many more algorithms out there that try to define perceptual brightness than just the two listed, and you probably want to use one of the more advanced human-perceptual color spaces out there, like HCL or CIECAM02, rather than RGB), so then it's just a matter of reversing the formula to generate colors within a particular luminance range.
Edit:
One of the great things about having a large diverse community like StackExchange is that there are programmers here working in all types of fields, and chances are good one of them's already asked/answered a question related yours or helpful to solving the problem you're working on.