"""Applies a random RGB color to all or selected layers (default is all layers)
Script by Mitch Heynick, 01.07.15"""
import rhinoscriptsyntax as rs
import scriptcontext as sc
import random

def RandomColorLayers():
    if "RCSL_Choice" in sc.sticky: sel_choice = sc.sticky["RCSL_Choice"]
    else: sel_choice = False
    choice=["Select","AllLayers","LayerRange"]
    gb=rs.GetBoolean("Layers to select?",choice,sel_choice)    
    if not gb: return
    if gb[0]:
        layers=rs.GetLayers("Select layers to randomize color")
        if not layers: return
    else:
        layers=rs.LayerNames()
    rs.EnableRedraw(False)
    for layer in layers:
        r=random.randint(0,255)
        g=random.randint(0,255)
        b=random.randint(0,255)
        rs.LayerColor(layer,(r,g,b))
    sc.sticky["RCSL_Choice"] = sel_choice
RandomColorLayers()