# Random sampling from the intersection of cube and simplex

I'm trying to find a way to randomly sample points from the intersection of the simplex $$\Delta_k$$, defined by $$$$\Delta_k : \{x_i\in\mathbb{R}^n\ |\ 0\leq x_i\leq k, \ x_1+x_2+\cdots+x_n = k\}$$$$ with $$0\leq k \leq n$$ and the unit cube defined by $$$$\{x_i\in\mathbb{R}^n\ |\ 0\leq x_i \leq 1\ \}$$$$ Now, I know how to obtain a uniform random sample on the simplex (e.g. from here https://cs.stackexchange.com/questions/3227/uniform-sampling-from-a-simplex) and the sampling is trivial on the cube, but how to tackle the intersection?

The intersection in some cases (i.e. for some values of $$k$$) is another simplex so the problem in those cases is solved, but for instance in the case $$n=3$$ and for some values of $$k$$ the intersection is a hexagon.

• Can you sample on the simplex and then throw out the result if it doesn't fall within the cube? Or is that impractical for the values of $n, k$ you're interested in? Commented Oct 5, 2021 at 16:11
• I could sample from the simplex but the ratio between the measure of the simplex and the intersection goes to zero for $k\rightarrow 0$ or $n$ so in those cases there would be a lot of trials to do before getting a sample on the spot Commented Oct 6, 2021 at 5:30
• cs.stackexchange.com/q/160050/755
– D.W.
Commented May 9, 2023 at 4:42