Add sample(_) and sample(_,_) to Random.

This commit is contained in:
Bob Nystrom
2016-02-09 07:24:45 -08:00
parent d4a4b26203
commit 8b36e2f00b
11 changed files with 248 additions and 5 deletions

View File

@ -94,6 +94,21 @@ Returns an integer between `start` and `end`, including `start` but excluding
System.print(random.int(-10, 10)) //> -6
System.print(random.int(-4, 2)) //> -2
### **sample**(list)
Selects a random element from `list`.
### **sample**(list, count)
Samples `count` randomly chosen unique elements from `list`.
This uses "random without replacement" sampling—no index in the list will
be selected more than once.
Returns a new list of the selected elements.
It is an error if `count` is greater than the number of elements in the list.
### **shuffle**(list)
Randomly shuffles the elements in `list`. The items are randomly re-ordered in