Main Content

Random sample

returns a vector of `y`

= randsample(`population`

,`k`

)`k`

values sampled uniformly at random, without
replacement, from the values in the vector `population`

.

returns a sample taken with replacement if `y`

= randsample(___,`replacement`

)`replacement`

is
`true`

, or without replacement if
`replacement`

is `false`

. Specify
`replacement`

following any of the input argument combinations
in the previous syntaxes.

uses a vector of nonnegative weights, `y`

= randsample(`population`

,`k`

,true,`w`

)`w`

, of the same length as
the vector `population`

, to determine the probability that a value
`population(i)`

is selected as an entry for
`y`

.

uses
the stream `y`

= randsample(`s`

,___) `s`

for random number generation. The option
`s`

can precede any of the input arguments in the previous
syntaxes. `s`

is a member of the `RandStream`

class.

To sample data randomly, with or without replacement, use `datasample`

.

`datasample`

| `rand`

| `randperm`

| `RandStream`