How can you batch rename layers?

using rhino7 , random scripts found here in this forum, and elsewhere seem to not be working
I’m not really into rhino scripting, anything that I try fails like:

I got hundreds of layers, I need to rename them either in some random name or generic name like layer1, layer2 and etc

import rhinoscriptsyntax as rs
import random
import string

def AddPrefixToLayerName(layer_id, prefix):
    sublayers = rs.LayerChildren(layer_id)
    if sublayers:
        for s_layer_name in sublayers:
            s_layer_id = rs.LayerId(s_layer_name)
            AddPrefixToLayerName(s_layer_id, prefix)

    new_name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
    rs.RenameLayer(layer_id, new_name)

def RenameAllLayers():
    layer_names = rs.LayerNames()
    top_layers = [layer_name for layer_name in layer_names if not rs.ParentLayer(layer_name)]
    top_layer_ids = [rs.LayerId(tl_name) for tl_name in top_layers]

    for layer_id in top_layer_ids:
        AddPrefixToLayerName(layer_id, "")
        
RenameAllLayers()

In Rhino 8 WIP, you can use the new Rhino components like this:

rename_layers.gh (16.9 KB)

In v7 or before Human plugin in grasshopper can do it.

There are others too… elefront I think should work for that as well.

Not in front of a computer so can’t share anything rn…