I would like to generate a plane and add hills to it. What would be the correct math for this?

I have the code for a basic grid in Unity that generates a set of vertices. That much of this works, however I’d like to also create dips and hills in the surface. I’ve tried altering the y property, however that’s causing things to go rather weird. This is the code I have so far.

    void Start () {
        vertices = new Vector3[(xSize + 1) * (ySize + 1)];
        for (int i = 0, y = 0; y <= ySize; y++, i++)
        {
            for (int x = 0; x <= xSize; x++)
            {
                vertices *= new Vector3(x, i + y, y);*

}
}
}
When I alter the Y, it causes everything to go… screwy. Sometimes all vertices to the left, others all to the right. How can I correct the math to generate smooth random hills? (Ignoring the i/y, which is just testing to try to get the generation working, however where I thought the code for the displacement would go).

Generation of random hills is usually done through multiple layers (usually using Fractal Brownian Motion) of Perlin/Simplex noise. Those would give you a float[,] which you could then apply to an array of vertices like so:

Vector3[] vertices = new Vector3[xSize * ySize];
float[,] noise = GetNoise(); //use perlin/simplex noise

for (var j = 0; j < ySize; j++){
    for (var i = 0; i < xSize; i++){
         vertices[i + (j * xSize)] = new Vector3(i, noise[i,j], j);
    }
}

The actual generation of perlin/simplex noise is fairly complex but there are a lot of resources online.