Linked Questions

3 votes
4 answers
3k views

Random real numbers that sum up to specific value [duplicate]

In here, it works with "Integer". What if I want 5 positive real numbers that sum to 1? RandomChoice[IntegerPartitions[100, {5}]]/100. That will work. But only ...
Chen Stats Yu's user avatar
6 votes
2 answers
3k views

How do I generate n random numbers with an extra condition [duplicate]

I need to generate n random numbers that would sum into a. And I can't find an elegant solution here: https://reference.wolfram....
skrat's user avatar
  • 1,275
3 votes
3 answers
859 views

Produce a probability vector with uniform distribution [duplicate]

A probability vector is a vector $\mathbf{p}=(p_1,p_2,\ldots,p_n)$ with the following properties: $\sum_{i=1}^{n}p_i=1$ $p_i\geq 0$ Assume that the set of all possible probability vectors is $\...
Math_Y's user avatar
  • 131
118 votes
7 answers
14k views

Generating visually pleasing circle packs

EDIT: (my conclusion and thank you note) I want to thank you all guys for this unexpected intellectual and artistic journey. Hope you had fun and enjoyed it the same as I did. I would like to ...
VividD's user avatar
  • 3,660
13 votes
11 answers
8k views

Random numbers that sum up to specific value

I would like to generate a list with random numbers, which add up to a specific value. While[Total[x] == 28, x = RandomInteger[{0, 28}, 5];Print[x]] The random ...
Bimmel's user avatar
  • 573
17 votes
6 answers
5k views

Vectors with a certain magnitude in Mathematica

For a user-specified magnitude, is there a way to have Mathematica produce any 3D vector with that magnitude?
user avatar
6 votes
4 answers
2k views

Random sampling of multiple integers with constant sum

I want to build a model of 40 geological layers, assuming each layer has equal chance to be one of the four types of rocks and the four types of rocks have equal chance to appear in any layer. The ...
yanfyon's user avatar
  • 594
6 votes
3 answers
764 views

How to generate a Markov Matrix efficiently

A Markov Matrix is a square matrix,which have two features: All elements great than or equal to $0$(But I hope all element great than or equal to $0.1$) All the columns add up to $1$ I have a custom ...
yode's user avatar
  • 26.8k
2 votes
3 answers
501 views

Random reals according to conditions

I'd like to create a list of triplets $(x,y,z)$ which satisfy the following properties: $$0<x<1/2 \\ 0<y<1/2-x \\ -1<z<-2(x+y)$$ Basically I would like to uniformly generate random ...
Sheheryar Zaidi's user avatar
7 votes
4 answers
461 views

How to generate two group of $n$ random numbers in $U(0,1)$ such that sum of these two groups equal? [closed]

I want to have two groups of $n$ random numbers $u_i$ and $v_i$ in $U(0,1)$, such that $\sum u_i = \sum v_i$ What I tried is: I can firstly get $u_i$ by ...
LifeWorks's user avatar
  • 427
6 votes
1 answer
2k views

Extending a ternary plot to a tetrahedron (using ListPlot)

I have been making ternary plots of data that is a list of sets of 3 numbers, where the numbers in each set sum to one (call this "DATA"). To do this, I first transform DATA onto the 2D surface with ...
jmbierna's user avatar
  • 369
6 votes
1 answer
686 views

Generate regularly spaced points from the surface of simplexes

I need to generate regularly spaced samples (points) from the surface of unit simplexes with 2 or greater vertices or end points. I can generate random samples pretty straightforwardly: ...
Jagra's user avatar
  • 14.4k
3 votes
1 answer
246 views

Generate a uniform distribution over an $n$-simplex employing quasi-random low-discrepancy points

This post is intended in a similar direction to an earlier one Can I use Compile to speed up InverseCDF? . I now wish to generate uniform points in an $n$-simplex (specifically $n=8$), making use of ...
Paul B. Slater's user avatar
0 votes
0 answers
323 views

Generating random matrices with a given $l_1$-norm

Let for any matrix $X$, its $l_1$-norm is given by $$\|X\|_1=\sum_{i,j}|x_{ij}|.$$ Let $x>0$ be given fixed number. How could I generate random quantum states $X$'s (i.e., positive semidefinite [i....
Marcus's user avatar
  • 143