Algorithm to generate repetitive sequence of fixed length

I am trying to create an algorithm to generate test cases. Each test case is an array of $ n$ natural integers which are randomly generated using a pseudo-random function. The bound for $ n$ is $ 0 < n \le 256$ .

Each array is generated using a “repetitiveness/noise factor”, $ r$ . If $ r = n$ , the elements of the array will all be individually computed with the pseudo-random function (therefore, the function is called $ n$ times). On the lower bound, $ r = 1$ , all the elements of the array are generated at once (function is called once). As an other example, if $ r = n-1$ , the first two elements will be calculated at once, while the remaining elements will be computed individually.

Spreading the repetition across the elements should be preferred over calculating a repetition once: $ [a, a, b, b, c]$ is preferred over $ [a, a, a, b, c]$ , even if both cases only call the pseudo-random function 3 times. As such, if $ n$ is an even number, and $ r = \frac n2$ , then the array should consist of $ r$ groups of 2 elements computed together.

If my explanation is not clear, perhaps some example data could help:

Given $ n = 5$ , $ r = 5$ , resulting array is $ [a, b, c, d, e]$

Given $ n = 5$ , $ r = 4$ , resulting array is $ [a, a, b, c, d]$

Given $ n = 5$ , $ r = 3$ , resulting array is $ [a, a, b, b, c]$

Given $ n = 5$ , $ r = 2$ , resulting array is $ [a, a, a, b, b]$

Given $ n = 5$ , $ r = 1$ , resulting array is $ [a, a, a, a, a]$