Create material, apply to layer and export to rmtl file

Here a simple example - I include at the beginning the contents of a Rhino Custom material saved as .rtml so you can see what the parameter possible for this particular material. I suggest you do so for all the material types that come with Rhino.

# Randomizer

"""
<xml>
	<material type-name="rcm-basic-material" render-engine-id="99999999-9999-9999-9999-999999999999" type-id="BA51C000-BA51-C000-BA51-C0BA51C00000" notes="" tags="" hidden="false" reference="false" auto-delete="false">
		<parameters>
			<bitmap-texture-on type="bool">false</bitmap-texture-on>
			<bitmap-texture-filter-on type="bool">true</bitmap-texture-filter-on>
			<bitmap-texture-amount type="double">1</bitmap-texture-amount>
			<bump-texture-on type="bool">false</bump-texture-on>
			<bump-texture-filter-on type="bool">true</bump-texture-filter-on>
			<bump-texture-amount type="double">1</bump-texture-amount>
			<transparency-texture-on type="bool">false</transparency-texture-on>
			<transparency-texture-filter-on type="bool">true</transparency-texture-filter-on>
			<transparency-texture-amount type="double">1</transparency-texture-amount>
			<environment-texture-on type="bool">false</environment-texture-on>
			<environment-texture-filter-on type="bool">true</environment-texture-filter-on>
			<environment-texture-amount type="double">1</environment-texture-amount>
			<version type="int">2</version>
			<diffuse type="color">0.980392158031464,0.980392158031464,0.980392158031464,0</diffuse>
			<specular type="color">1,1,1,0</specular>
			<shine type="double">1</shine>
			<transparency type="double">0</transparency>
			<reflectivity type="double">1</reflectivity>
			<ior type="double">1</ior>
			<transparency-color type="color">1,1,1,0</transparency-color>
			<reflectivity-color type="color">1,1,1,0</reflectivity-color>
			<emission type="color">0,0,0,0</emission>
			<ambient type="color">0,0,0,0</ambient>
			<flamingo-library type="string"/>
			<disable-lighting type="bool">false</disable-lighting>
			<fresnel-enabled type="bool">true</fresnel-enabled>
			<polish-amount type="double">1</polish-amount>
			<clarity-amount type="double">1</clarity-amount>
			<alpha-transparency type="bool">false</alpha-transparency>
		</parameters>
		<simulation>
			<ambient type="color">0,0,0,0</ambient>
			<diffuse type="color">0.980392158031464,0.980392158031464,0.980392158031464,0</diffuse>
			<emission type="color">0,0,0,0</emission>
			<specular type="color">1,1,1,0</specular>
			<reflection type="color">1,1,1,0</reflection>
			<shine type="double">1</shine>
			<transparency type="double">0</transparency>
			<reflectivity type="double">1</reflectivity>
			<ior type="double">1</ior>
			<fresnel-enabled type="bool">true</fresnel-enabled>
			<polish-amount type="double">1</polish-amount>
			<clarity-amount type="double">1</clarity-amount>
			<transparent type="color">1,1,1,0</transparent>
		</simulation>
	</material>
	<meta-data>
		<renderer-name>Generic</renderer-name>
		<type-name>Custom</type-name>
	</meta-data>
	<thumbnail>none</thumbnail>
</xml>
"""

import random
import scriptcontext as sc
import Rhino.Render as rr
import System.Drawing as sd

rms = [x for x in sc.doc.RenderMaterials]
if len(rms) > 0:
	rm = rms[0]
	rm.BeginChange(rr.RenderContent.ChangeContexts.Program)
	rm.SetParameter("diffuse", sd.Color.FromArgb(random.randint(0,255), random.randint(0,255), random.randint(0, 255)))
	rm.EndChange()

Run the script in a file that has one Custom material and pay attention to the color channel.

From the ChangeContexts enum for scripting purposes the only useful entries are UI, Program and Ignore. For scripts you generally use Program and Ignore, where the latter is for temporary changes.