# Getting random points on a mesh region

So I have a region defined by a MeshRegion,like

MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}]


Which I would like to pick some random points on its border, like {0.5,0.5} and {1,-0.25}. Converting to Graphics and Rasterize, then picking random points is a way, but it would cause serious slowing down as most of the space is used to store the non-boundary points, not to mention the decreased accuracy. So is there a way to get the random points directly from the MeshRegion? The accuracy should be changeable.

• why not RandomPoint[mr,10] where mr = MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}], Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}] ? – kglr Jun 3 '18 at 9:21

## 1 Answer

mr = MeshRegion[{{0, 0}, {1, 1}, {2, 1/2}, {2, -1/2}}, {Line[{1, 2}],
Line[{2, 3}], Line[{3, 4}], Line[{4, 1}]}];
rp = RandomPoint[mr, 50];
Show[mr, Epilog -> {Red, PointSize[Large], Point @ rp}] See the section RandomPoint >> Scope for examples of various forms the first argument of RandomPoint can take: 