# Generating random samples in N dimensions in Python [closed]

I am trying to generate N random samples in J dimensions subject to a constraint. Each dimension j is bounded by a unique "Lower_Bound" and "Upper_Bound," which both are bounded [0,1]. The constraint is that the sum across j for each sample n = 1.0. EG, for each n, the sum of j(i) = 1.

Owing to the potential of uniques range for every dimension, it is not obvious to me how I can generate the samples to ensure a uniform distribution over the space. Simply creating an RV for each j-th element in order would bias the results.

I have come up a (possibly inelegant) solution: I generate an ordered list of length J, which I shuffle for every iteration of N. I then using each shuffled list to generate j(i).

Query - does this generate samples uniformly distributed over the space, and is there a statistical test I can perform to quantify the uniformity? By uniformly distributed, I mean there is an equal probability of picking any point on the J dimensional surface.

The reason I raise this point is because most of the sampling algorithms I have come up with have subtle biases which result in some parts of the space being sampled more than others.

I need an analogue to a Gini coeffecient, I am out of my depth here!

• Although this is asked in conjunction w/ Python code, it seems like there is a meaningful statistical question underneath it. I am inclined to leave this open. Nov 20, 2015 at 19:03
• @gung I agree. Voting leave open. Nov 20, 2015 at 20:37
• What do you mean by "uniformly distributed over J space"? Is it that you'd like each of N J-dimensional variables to be roughly even? Meaning you'd prefer vectors like $\langle 0.5 0.5 \rangle$ to $\langle 0.99 0.01\rangle?$ Nov 20, 2015 at 20:41
• Thanks, that's helpful. And over what dimension must they sum to 1? Is that across your sample of $n$, the $j$ dimension must sum to 1? (A small sample of how the data should look might help potential answerers see what you're aiming for.) Nov 21, 2015 at 15:16
• I really don't understand this question: something about "The constraint is that the sum across j for each sample n = 1.0." is garbled. Further references to "J space" and "hypersurface" and "unique length" in comments are equally puzzling--these terms, since they are used in such a vague manner, could be interpreted in many different ways. Could you please edit the question as requested by @SeanEaster?
– whuber
Nov 21, 2015 at 15:41