random extruded grid

python - 2018-03-17 17:06:52
  (from https://blender.stackexchange.com/a/24472/23036 )
extrude all faces of a grid in a random way
import bpy
import bmesh
from mathutils import Vector
from random import random

bpy.ops.mesh.primitive_grid_add(x_subdivisions=10, y_subdivisions=10, radius=5)
ob = bpy.context.object
me = ob.data

bm = bmesh.new()
bm.from_mesh(me)
faces = bm.faces[:]

for face in faces:
    r = bmesh.ops.extrude_discrete_faces(bm, faces=[face])
    bmesh.ops.translate(bm, vec=Vector((0,0,random()*2)), verts=r['faces'][0].verts)

bm.to_mesh(me)
me.update()