I'm trying to produce $n$ random samples from a list, but not all samples, and I'd like the samples to not repeat in the same execution of the command. If I'm not mistaken, something like Permutations[]
for not all permutations, or RandomPermutation
for a list, or a hypothetical MultipleRandomSample[]
. Is there something I'm misinterpreting or a way to generate such collections of random samples?
Edit: What I'm calling random samples are actually subsets, since they are fixed size and order doesn't matter. Now, I only need to take $n$ random subsets from a set.
RandomSample
repeats "subsets":
Table[RandomSample[{2, 3, 5, 8}, 3], 10]
{{3, 2, 5}, {5, 8, 2}, {8, 3, 2}, {8, 5, 2}, {2, 3, 5}, {8, 2, 3}, {2,
3, 8}, {2, 5, 3}, {8, 3, 5}, {2, 8, 5}}
Subsets
is adequate, but it gives all subsets, and I wish to find $n$ random subsets:
Subsets[{2, 3, 5, 8}, {3}]
{{2, 3, 5}, {2, 3, 8}, {2, 5, 8}, {3, 5, 8}}
A simulated result would be:
Table[Op[{2, 3, 5, 8}, {3}],3]
{{{2, 3, 5}, {2, 3, 8}, {2, 5, 8}},
{{2, 3, 5}, {2, 3, 8}, {3, 5, 8}},
{{2, 3, 8}, {2, 5, 8}, {2, 5, 8}},
{{2, 3, 8}, {2, 5, 8}, {2, 5, 8}}(*repetitions are ok*)}
Is there a way to produce such collections of subsets without obtaining all subsets, randomizing, and taking $n$?
Table[RandomSample[list, k], {n}]
suit your needs? $\endgroup$RandomSample[]
could repeat. $\endgroup$RandomSample
... never samples ... more than once." $\endgroup$Partition[RandomSample[list], k]
to generate all non-overlappingk
-samples, and take the first few as needed? $\endgroup$