Help with 3D data representation algorythm
An example

import bpy
import bmesh
from random import uniform

mesh  = bpy.data.meshes.new("Mesh")
obj   = bpy.data.objects.new("Mesh", mesh)
scene = bpy.context.scene
scene.objects.link(obj)

bm = bmesh.new()

verts_b = [bm.verts.new((i, 0.0,               0.0)) for i in range(20)]
verts_t = [bm.verts.new((i, 0.0, uniform(1.0, 3.0))) for i in range(20)]

# create edges
# for i in range(19):
#    bm.edges.new((verts_t[i], verts_t[i+1]))

faces = [
    bm.faces.new((
        verts_b[i]  , verts_b[i+1],
        verts_t[i+1], verts_t[i]
    ))
    for i in range(19)
]

result = bmesh.ops.extrude_discrete_faces(
    bm, faces=faces, use_select_history=False)

for f in result['faces']:
    amount = uniform(1.0, 2.0)
    for v in f.verts:
        v.co.y += -amount

bm.to_mesh(mesh)
bm.free()