up previous next
RandomSubset

random subset

Syntax
RandomSubset(L: LIST, K: INT): LIST

Description
The function returns a random subset of L of cardinality K . This function can be quite useful for testing properties on some subsets of a large list when testing on all of them would be unfeasible in time and memory (see also subsets ).

NOTE: the resulting list is sorted as in L .

Example
/**/ RandomSubset(["a","b","c","d","e","f","g","h"], 5);
["a", "c", "d", "f", "h"]

/**/ indent([RandomSubset(1..1000, 10) | i in 1..4]);
[
  [160, 182, 215, 219, 349, 588, 628, 811, 886, 905],
  [23, 103, 315, 451, 531, 539, 571, 846, 858, 876],
  [24, 230, 240, 278, 380, 421, 495, 505, 665, 788],
  [81, 274, 299, 378, 414, 616, 828, 844, 870, 946]
]
/**/ binomial(1000, 10);  --> too many to fit in memory ;-)
263409560461970212832400

See Also