Script random layers by specific layer number

Hello everyone,
just figuring out for a design project whether there is a script to distribute all items on different layers to render them later in different colours and materials. I have one to create so many layers as items (;; but I want to set a certain layer number i.e. 8 different layers (which shall be colours or materials later) and then distribute all existing objects (cubes in this setting) to render the cubes in different assigned colours/materials. could also work by material or object colour as the scripts above. Thank you for your massive help on this!