Generating lists of numbers which sum to points on a normal distribution

In short, I would like to take a number, say N, and generate a list of n numbers which will sum to N with the constraint is that N itself is a number from a nearly normal distribution with, say $$\mu \pm 4\sigma$$ for some $$\mu$$ and $$\sigma$$.

The way I have been going about this is to build a list for each number N (which was generated on the nearly normal distribution) but am wondering if I don't need to do this. That instead of generating a number N and building an exact list, I could build lists in which each sum to N on a nearly normal distribution?

So basically the lists (which have minimum and maximum values) have to sum to numbers, the totality of which constitute a nearly normal distribution.

I will have k lists, each with m numbers of questions in which, in each list the numbers can range from 0 to r. There is varying number of samples, though at least 100.

More in depth with an example.

Say a list is made of 20 questions, each of which can have a value from 0 to 4. I want to generate data points (such as N on the larger normal distribution) in between the values of 0 and 80 (as 0 * 20 = 0 and 4 * 20 = 80).

Now one way would be to try to divide each N and divide the numbers up over the 20 questions. So for example, say I generate three data points between 0 and 80: $$Val1 = 32$$, $$Val2 = 44$$, and $$Val3 = 7$$, then for each of these three points I would three lists of 20 values between 0 and 4 say:

For $$Val1$$, $$32 = \sum([3,2,0,1,1,4, ... , 3])$$

For $$Val2$$, $$44 = \sum([2,3,2,3,1,4, ... , 2])$$

For $$Val3$$, $$7 = \sum([1,0,0,0,1,0, ... , 0])$$

Again, maybe I don't even have to generate numbers on a normal distribution and divide each over individual lists to get the result of having many lists, each of which sum to a number on a larger normal distribution.

• Thanks for showing some of the things you tried. But in the midst of that discussion, I get lost at several points. (a) If you have min and max restrictions, then technically you can't have a normal distribution because a normal distribution extends to $\pm \infty$ even though almost all of its probability is in, say $\mu \pm 4\sigma.$ (b) How many 'lists' and how many elements in each list? (c) How large should the overall normal sample be? (d) Do you have a target $\mu$ and $\sigma$ for the overall normal distribution? Jun 19, 2019 at 6:15
• Here is a simulation expt for you to consider. Suppose I want 25 normally distributed numbers with mean 80 and total 2000. Then in R: set.seed(618); x.tmp = rnorm(25, 80, 4); x = 80*x.tmp/mean(x.tmp) Then mean(x) returns 80 and sum(x) returns 2000, as required. Jun 19, 2019 at 6:33
• Now if I take those 25 numbers, how would I generate a list of Scores for each? I posted an answer to the question in which I can do this with Python's version of R's rnorm() function. The lists don't always sum up to N, just on average. If I were to just take the sums of each of the lists that I am generating, should they be a true normal distribution? I would think so as the lists on average sum to each N which was taken from a normal distribution. Though graphing the curve might look like it does, I am curious to as if it is really skewed in some small way. Jun 19, 2019 at 9:41
• Although I cannot tell what you're trying to do, your example looks remarkably like what is requested at stats.stackexchange.com/questions/129789, which has a simple, efficient solution.
– whuber
Nov 18, 2020 at 23:13

The code below gives a solution to the problem in which each of the lists, such as those as $$Val1, Val2, ...$$ are generated statistically in that the sum of list elements for each generated N will not always (or usually) sum to the exact number. They however will do so on average and is done through the function: np.random.normal(Score_Mean, Score_Sigma, NumberQuestions).

The code is compatible with Python 3.7. Similar to the program R's rnorm(...) function Python has the function: np.random.normal(...) which takes the general parameters such as the mean and standard deviation, but also the number of list elements you would like the generated number normally distributed over.

import numpy as np

NumberQuestions = 20
NumberofSubjects = 5
Score_Sigma = 1
All_Scores_List = []

Scores = np.random.normal(40, 10, NumberofSubjects)

for Score in Scores :
Score_Mean = Score/NumberQuestions
# Use the mean score (Score_Mean) to populate another list which on AVERAGE would average to Score_Mean
Score_List = np.random.normal(Score_Mean, Score_Sigma, NumberQuestions)
All_Scores_List.append((np.round(Score_List)).astype(int))

print(Scores)
print(All_Scores_List)