Suppose that you have a set A in Julia. How do you generate a random subset from A? Is there any package or special function to do this?.
Suppose that you have a set A in Julia. How do you generate a random subset from A? Is there any package or special function to do this?.
The best method I can think of for sampling without replacement is to use the sample method from StatsBase (Doc). Unfortunately, this method currently only works for indexable collections. So you would have to convert your Set to an Array first and your sample back to Set.
using StatsBase
A = Set([1, 2, 3, 4, 5])
S = Set(sample(collect(A), 3, replace = false))