I know, whatever comes out will likely be inefficient.
Still your proposed solution is not what i desire. It just fills the three values inside each pixel with random values out of the set {0,1,2,3,4} assuming a uniform distribution. I don’t want that. I want to fill it with actual pixels fro my image a, which requires me to 1. keep the RGB-triplets together 2. not sample over unique triples but over all triplets.