How to generate numbers in range with specific average with Python?
<p>For example I would like to generate 22 numbers between 20 and 46 with an average value of 27. And I would like the numbers to cover the range as well as possible.</p>

<p>EDIT:
These numbers don't need to be random.</p>

<p>Not optimal in terms of covering the range as much as possible, but you can try this:</p>

<pre><code>def GenerateArr(count,minimum,maximum,average):
    arr = []
    diff = 1
    while len(arr) &lt; count-1:
        if minimum &lt;= average-diff and average+diff &lt;= maximum:
            arr.append(average-diff)
            arr.append(average+diff)
            diff += 1
        else:
            arr.append(average)
            diff = 1
    if len(arr) &lt; count:
        arr.append(average)
    return arr

print GenerateArr(22,20,46,27)
</code></pre>

python math