Hello,
You can do it without any script, for those cases:
1-Your object have polygon groups of the same polygon count(e.g. brick wall)
Create a new material, then for the color channel insert variation shader, then enable polygon variation, and change the steps to
the amount of polygons each group has.
2-Your object does't have an even poly count for each group
Put your object inside a fracture object(NOT voronoi fracture!), change the mode from straight to explode segments and connect
and put the material from above on it, disable the polygons option and you get the result you are after.
P.S. The result will be seen in renderer only and some render engine doesn't support it. Also this doesn't output a vertex color, if you have to get it as a vertex color you may need a plugin or a script.
Best regards,