Randomizing all class variables in constructor c++
In theory, I think this is allowed because your Items are trivial types, but this is pretty ugly.

I think you can do better using std::array.

struct _color { uint8_t r; uint8_t g; uint8_t b; uint8_t a;};


could be

struct _color {
    auto&amp; r() { return data[0]; }
    // etc
    void randomize() { /* fill data with random stuff */ }
    private:
        std::array&lt;uint8_t, 4&gt; data;
};




P.S. I think you will find that uniformly randomly setting r, g, b, and a doesn't look random to humans.



P.P.S.  There is a proposal to add something like this:

_color color;
for... (auto&amp; component : std::meta::members(color)) {
    // do stuff with component
}


I haven't followed this proposal but it sounds like it would help here.