#include <iostream>
#include <random>
struct Color {
Color(unsigned char r, unsigned char g, unsigned char b) : r(r), g(g), b(b) {}
unsigned char r, g, b;
};
std::ostream &operator<<(std::ostream &out, const Color &c) {
return out << "(" << (int)c.r << ", " << (int)c.g << ", " << (int)c.b << ")";
}
Color random_color(int j, std::mt19937 &gen) {
std::uniform_int_distribution<int> distrib(1, 0xFFFFFF);
int color = distrib(gen);
int r = color & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 16) & 0xFF;
double l = sqrt(0.299*r*r + 0.587*g*g + 0.114*b*b);
double c = j/l;
return Color(c*r, c*g, c*b);
}
int main() {
std::random_device rd;
std::mt19937 gen(rd());
for (int j : { 0, 1, 2, 10, 50, 100, 200, 243, 254, 255 }) {
std::cout << "j = " << j << ", color = " << random_color(j, gen) << std::endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cmFuZG9tPgoKc3RydWN0IENvbG9yIHsKCUNvbG9yKHVuc2lnbmVkIGNoYXIgciwgdW5zaWduZWQgY2hhciBnLCB1bnNpZ25lZCBjaGFyIGIpIDogcihyKSwgZyhnKSwgYihiKSB7fQoJdW5zaWduZWQgY2hhciByLCBnLCBiOwp9OwoKc3RkOjpvc3RyZWFtICZvcGVyYXRvcjw8KHN0ZDo6b3N0cmVhbSAmb3V0LCBjb25zdCBDb2xvciAmYykgewoJcmV0dXJuIG91dCA8PCAiKCIgPDwgKGludCljLnIgPDwgIiwgIiA8PCAoaW50KWMuZyA8PCAiLCAiIDw8IChpbnQpYy5iIDw8ICIpIjsKfQoKQ29sb3IgcmFuZG9tX2NvbG9yKGludCBqLCBzdGQ6Om10MTk5MzcgJmdlbikgewoJc3RkOjp1bmlmb3JtX2ludF9kaXN0cmlidXRpb248aW50PiBkaXN0cmliKDEsIDB4RkZGRkZGKTsKCWludCBjb2xvciA9IGRpc3RyaWIoZ2VuKTsKCWludCByID0gY29sb3IgJiAweEZGOwoJaW50IGcgPSAoY29sb3IgPj4gOCkgJiAweEZGOwoJaW50IGIgPSAoY29sb3IgPj4gMTYpICYgMHhGRjsKCQoJZG91YmxlIGwgPSBzcXJ0KDAuMjk5KnIqciArIDAuNTg3KmcqZyArIDAuMTE0KmIqYik7Cglkb3VibGUgYyA9IGovbDsKCXJldHVybiBDb2xvcihjKnIsIGMqZywgYypiKTsKfQoKCmludCBtYWluKCkgewoJc3RkOjpyYW5kb21fZGV2aWNlIHJkOwoJc3RkOjptdDE5OTM3IGdlbihyZCgpKTsKCQoJZm9yIChpbnQgaiA6IHsgMCwgMSwgMiwgMTAsIDUwLCAxMDAsIDIwMCwgMjQzLCAyNTQsIDI1NSB9KSB7CgkJc3RkOjpjb3V0IDw8ICJqID0gIiA8PCBqIDw8ICIsIGNvbG9yID0gIiA8PCByYW5kb21fY29sb3IoaiwgZ2VuKSA8PCBzdGQ6OmVuZGw7IAoJfQp9
j = 0, color = (0, 0, 0)
j = 1, color = (0, 1, 1)
j = 2, color = (1, 1, 4)
j = 10, color = (8, 10, 12)
j = 50, color = (54, 25, 104)
j = 100, color = (54, 116, 99)
j = 200, color = (249, 189, 55)
j = 243, color = (165, 26, 190)
j = 254, color = (85, 65, 119)
j = 255, color = (49, 245, 130)