Is it possible to assign a "run probability" to any function?
fn = RandomChoice[{#3, 1 - #3} -> {RandomSample[#1, #2], {}}] &;
Use:
fn[list,number_of_samples,probability_of_sample_success]
Example:
fn[{1, 2, 3, 4, 5, 6}, 3, .3]
{2,1,5}
fn[{1, 2, 3, 4, 5, 6}, 3, .3]
{1,4,5}
fn[{1, 2, 3, 4, 5, 6}, 3, .3]
{}
You can use RandomChoice
to do weighted random choice of the sampling functions and use Through
to apply those functions to your data.
d = {1, 2, 3, 4, 5, 6};
SeedRandom[15]
Through[RandomChoice[{0.7, 0.3} -> {RandomSample[#, 1] &, Nothing &}, 12][d]]
(* {{3}, {5}, {1}, {6}, {1}, {4}, {4}, {3}, {3}} *)
SeedRandom[15]
Through[RandomChoice[{0.7, 0.3} -> {RandomSample[#, 1] &, None &}, 12][d]]
(* {None, None, {3}, {5}, {1}, {6}, {1}, {4}, {4}, None, {3}, {3}} *)
Perhaps this:
d = {1, 2, 3, 4, 5, 6};
RandomChoice[
Flatten@{70, ConstantArray[30/Length[d], Length[d]]} ->
{{}, Sequence @@ d}
]
Let's check that it does what you want by drawing 10,000 samples:
RandomChoice[
Flatten@{70, ConstantArray[30/Length[d], Length[d]]} ->
{{}, Sequence @@ d},
10000
] // Counts
(* Out: <|{} -> 6998, 3 -> 478, 2 -> 481, 1 -> 489, 5 -> 494, 4 -> 554, 6 -> 506|> *)
The frequency of {}
(i.e. the "no sample" response) is 6998/10000, i.e.pretty close to 70%. The others are pretty evenly distributed as well.