Skip to main content

Random.items

Random.itemsvcountwith_replacement

Group: Random

Documentation​

Returns a new Vector containing a random sample of the input vector, with or without replacement.

Arguments​

  • vector: The Vector to take items from.
  • count: The number of items to return.
  • with_replacement: If false, each value in the Vector can only be selected once during a single call; the returned values will contain no duplicates. If true, values from the Vector can be returned multiple times and duplicates are possible.

Examples​

Sample a vector.​

      import Standard.Base.Random.Random

items = Random.items [1, 2, 3, 4]

Remarks​

Selection without replacement​

If with_replacement is false, and count is equal to the size of the collection, a random permutation of the collection is returned. If with_replacement is false, and count is greater than the size of the collection, an Illegal_Argument error is thrown. (If count is greater than the size of the collection, items will run out of values to choose from, and will not be able to return enough values.)