Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to cover a particular subregion of the x-y plane with a random distribution.

As this particular region is not a circle I encounter some problems declaring the permitted zone where to put points.

The points must NOT be drawn in the blue zone. As in the graphenter image description here

And I use the following code to drawing the graph:

mu = 0.000954;
h = x^2 - y^2 + 2 (1 - mu)/Norm[x + mu] + 2 mu/Norm[1 - x - mu];
S = 
  RegionPlot[h < 3.07, {x, -2, 2}, {y, -2, 2}, 
    Mesh -> None, PlotPoints -> 200, Axes -> True, Frame -> False]

Where h is the function.

P.s.: the drawing process is a bit long if you use more then 200 points, so keep this not so high.

share|improve this question
up vote 5 down vote accepted

How about

f[x_, y_] = h - 3.07;

Then, drawing candidates

dat = {RandomVariate[UniformDistribution[{-2, 2}], np], 
       RandomVariate[UniformDistribution[{-2, 2}], np]} // Transpose;

and selecting

Show[Select[dat, f @@ # > 0 &] // ListPlot[#, AspectRatio -> 1] &, S]


the corresponding data can be exported as


$cat test.dat

share|improve this answer
Thanks a lot !!! A very stupid question, if i want to save the coordinates of these points in a file how i can do that? THANKS ! – Panichi Pattumeros PapaCastoro Apr 6 '14 at 14:36
in what format? – chris Apr 6 '14 at 14:41
I solve by mayself the problem of output. Just to take the data=Select[] also out from the Show and than use Export['output.dat',data]. – Panichi Pattumeros PapaCastoro Apr 6 '14 at 15:13
UniformDistribution can represent 2D distribution: dat = RandomVariate[UniformDistribution[{{-2, 2}, {-2, 2}}], np]. (+1 for post-Select.) – Silvia Apr 6 '14 at 22:38
@Silvia thanks. I thought it would be called Multi UniformDistribution – chris Apr 7 '14 at 11:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.