The diamond square thing sounds simple enough but coding it is a bit more difficult. I started coding it a while back for a terrain coding challenge but did not finish it. However, here is the final code. It also does some basic smoothing and normal setting. You may only be interested in the diamond square bit.
+ Code Snippetset display mode 1024,768,32
sync on : sync rate 60 : autocam off : randomize timer()
set camera range 1,5000
` make a texture
cls rgb(0,255,0)
ink rgb(255,255,255),0
box 1,1,8,8
get image 1,0,0,8,8,1
av as float
rn as float
s=64 : ` matrix units and array size; must be a power of 2
m=2000 : ` size of matrix in db units
rn=0.2 : ` bigger numbers = smoother, smaller = spikier
smt=3 : ` how many times to smooth matrix
dim a(s,s,1) as float
make matrix 1,m,m,s,s
prepare matrix texture 1,1,1,1
cull=1
set matrix 1,0,0,cull,1,1,1,1
` do the diamond square algorithm
` paying special attention to wrapping around
c=s
repeat
for z=0 to (s-c) step c
for x=0 to (s-c) step c
av=(a(x,z)+a(x+c,z)+a(x,z+c)+a(x+c,z+c))/4.0
av=av+((-100+rnd(200))/rn)
a(x+(c/2),z+(c/2))=av
next x
next z
w=1
for z=0 to (s-(c/2)) step (c/2)
for x=0 to (s-c) step c
x2=x+(w*(c/2))
av=a(x2,z+(c/2))+a(x2+(c/2),z)
if x2=0
av=av+a(s-(c/2),z)
else
av=av+a(x2-(c/2),z)
endif
if z=0
av=av+a(x2,s-(c/2))
else
av=av+a(x2,z-(c/2))
endif
av=av/4.0
av=av+((-100+rnd(200))/rn)
a(x2,z,0)=av
if x2=0 then a(s,z,0)=av
if z=0 then a(x2,s,0)=av
next x
w=1-w
next z
c=c/2
rn=rn*2.0
until c < 2
` smooth the result
for multiple=1 to smt
for x=0 to s-1
x2=x-1 : if x2 < 0 then x2=s-1
for z=0 to s-1
z2=z-1 : if z2 < 0 then z2=s-1
v1#=a(x2,z+1,0)
v2#=a(x,z+1,0)
v3#=a(x+1,z+1,0)
v4#=a(x+1,z,0)
v5#=a(x+1,z2,0)
v6#=a(x,z2,0)
v7#=a(x2,z2,0)
v8#=a(x2,z,0)
av#=(v1#+v2#+v3#+v4#+v5#+v6#+v7#+v8#)/8.0
a(x,z,0)=av#
next z
next x
for f=0 to s
a(s,f,0)=a(0,f,0)
a(f,s,0)=a(f,0,0)
next f
next multiple
` calculate normals
for x=0 to s
x2=x+1 : if x=s then x2=1
for z=0 to s
n#=1.0
a1#=a(x,z,0)
z2=z+1 : if z=s then z2=1
a2#=a(x2,z2,0)
ar#=a1#-a2#
if a1# > a2#
tw#=m*1.0/s
if ar# > tw#
n#=0
else
n#=ar#/(tw#/100.0)
n#=(1.0-(n#/100.0))
endif
endif
a(x,z,1)=n#
next z
next x
` update matrix from array
for z=0 to s
for x=0 to s
av=a(x,z,0)
n#=a(x,z,1)
if x <> s and z <> s
set matrix tile 1,x,z,1
endif
set matrix height 1,x,z,av
if n# < 1.0
set matrix normal 1,x,z,n#,n#,0
endif
next x
next z
update matrix 1
ink rgb(255,255,255),0
g=get ground height(1,m/2,m/2)
position camera m/2,m/2,-m/8
pitch camera down 45
do
u=0
if upkey() then shift matrix up 1 : u=1
if downkey() then shift matrix down 1 : u=1
if leftkey() then shift matrix left 1 : u=1
if rightkey() then shift matrix right 1 : u=1
if u=1 then update matrix 1
text 0,0,"Scroll matrix with cursors"
sync
loop