There's a formula for this:

Where:

- a is the maximum number of Berries that can appear on the plant

- b is the minimum number of Berries that can appear on the plant

- c is a number randomly chosen between a and b, inclusive

- d is the number of growth stages during which the plant was watered

Source: Bulbapedia