mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Add Random.shuffle().
This commit is contained in:
23
test/random/shuffle.wren
Normal file
23
test/random/shuffle.wren
Normal 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
|
||||
Reference in New Issue
Block a user