Add Random.shuffle().

This commit is contained in:
Bob Nystrom
2016-02-07 10:38:39 -08:00
parent 79558d95e5
commit d4a4b26203
4 changed files with 67 additions and 0 deletions

23
test/random/shuffle.wren Normal file
View File

@ -0,0 +1,23 @@
import "random" for Random
var random = Random.new(12345)
// Empty list.
var list = []
random.shuffle(list)
System.print(list) // expect: []
// One element.
list = [1]
random.shuffle(list)
System.print(list) // expect: [1]
// Given enough tries, should generate all permutations.
var hits = {}
for (i in 1..200) {
var list = [1, 2, 3, 4]
random.shuffle(list)
hits[list.toString] = true
}
System.print(hits.count) // expect: 24