n-of3.1

n-of size agentset n-of size list

From an agentset, reports an agentset of size size randomly chosen from the input set, with no repeats.

From a list, reports a list of size size randomly chosen from the input set, with no repeats. The items in the result appear in the same order that they appeared in the input list. (If you want them in random order, use shuffle on the result.)

It is an error for size to be greater than the size of the input.

If size is fractional, it will be rounded down to the nearest integer (4.5 becomes 4, 10.9 becomes 10).

ask n-of 50 patches [ set pcolor green ]
;; 50 randomly chosen patches turn green

See also one-of and up-to-n-of, a version that does not error with a size greater than the size of the input.

Take me to the full NetLogo Dictionary