# How to define a smooth function of random bumps in a plane?

I would like to define a simple function that gives random smooth bumps in a plane, a bit like the clumsy picture below, but it should be continuous:

Plot3D[RandomReal[{-1, 1}], {x, 0, 5}, {y, 0, 5}]


As a function of both $$x$$ and $$y$$, it should be smooth everywhere and be differentiable at least once. How can we define such a function RandomFun[x, y] (pun intended) with Mathematica?

Ideally, it should be as simple as possible and be valid for Mathematcia 7 (RandomFunction doesn't seem to be recognized with this version). Please, nothing fancy. Just the simplest way to get smooth bumps of height between -1 and 1.

• What's wrong with tt = Table[RandomReal[{-1, 1}], {x, 0, 5}, {y, 0, 5}];ff = ListInterpolation[tt];Plot3D[ff[x, y], {x, 0, 6}, {y, 0, 6}] Dec 9, 2020 at 18:11

Pick up the points

tt = Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, 5}, {y, 0, 5}];


Interpolate

ff = Interpolation[Flatten[tt, 1], Method -> "Spline"];


Plot

Plot3D[ff[x, y], {x, 0, 5}, {y, 0, 5}]


More points

tt = Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, 5, 0.25}, {y, 0, 5,
0.25}];    ff = Interpolation[Flatten[tt, 1], Method -> "Spline"];
Plot3D[ff[x, y], {x, 0, 5}, {y, 0, 5}, PlotPoints -> 50, Mesh -> None];


So if you want to wrap it up

Randfun:=
Module[{tt =
Table[{x, y, RandomReal[{-1, 1}]}, {x, 0, 5, 1}, {y, 0, 5, 1}]},
Interpolation[Flatten[tt, 1], Method -> "Spline"]
]


Then

Table[Plot3D[Randfun[x, y] // Evaluate, {x, 0, 5}, {y, 0, 5},
PlotPoints -> 50, PlotRange -> All], {2}, {2}]


Conversely, if you want to keep the same random bumps

ff1 = Randfun[x, y];
Table[ContourPlot[ff1, {x, 0, 5}, {y, 0, 5}], {2}]


If you want only a few point above sea level:

tt = Table[{x, y, z = RandomReal[{-1, 1}]; If[z > 0.75, z, 0]}, {x, 0, 5, 1/2}, {y, 0, 5, 1/2}];
ff = Interpolation[Flatten[tt, 1], Method -> "Spline"];
Plot3D[ff[x, y], {x, 0, 5}, {y, 0, 5}, PlotPoints -> 50, Mesh -> None,
PlotRange -> All]


• I think it's a proper solution! Thanks a lot! I'll mark your answer after a while, in case someone else find something prettier.
– Cham
Dec 9, 2020 at 18:30
• What to add, if you need the random bumps to stay the same, after a first pass?
– Cham
Dec 9, 2020 at 19:00
• Ok, it's trivial: SeedRandom[0]. Sorry for this. But your answer is awesome!
– Cham
Dec 9, 2020 at 19:08
• I am wondering, your function is everywhere hilly. Can one use your method to have essentially a flat plane with some random bumps here and there? Dec 11, 2020 at 11:55
• @yarchik it seems that, to my understanding, what you’re asking for is dependent upon the domain of the plane you’re displaying relative to the range chosen for the RandomReal function being used. Dec 11, 2020 at 14:41