If the number of possible points is large, than enumerating them all and taking a random sample won't be feasible. For example, suppose you have integer points in a 1000 x 1000 x 1000 box. Then, the number of possible points is 10^9, and it is unlikely that your computer will be able to generate the full list. Instead, it makes sense to index the points, and take a random sample of the indices, and then convert the indices to a point. For instance, in this example, there are 10^9 indices, and we can convert any index to a point using IntegerDigits
, for example:
IntegerDigits[13412343, 1000]
{13, 412, 343}
So, to find 10 random sample indices, we can do:
SeedRandom[1]
indices = RandomSample[0 ;; 10^9-1, 10]
{877665282, 101700636, 562018428, 288541214, 403280597, 238031837, 817685571, \
339828267, 510012226, 749565074}
The key here is that RandomSample
can accept a span object instead of a list of 10^9 integers. Then, convert them to points with IntegerDigits
:
IntegerDigits[indices, 1000]
{{877, 665, 282}, {101, 700, 636}, {562, 18, 428}, {288, 541, 214}, {403, 280,
597}, {238, 31, 837}, {817, 685, 571}, {339, 828, 267}, {510, 12,
226}, {749, 565, 74}}