Add a random module.

This commit is contained in:
Bob Nystrom
2015-10-17 11:03:15 -07:00
parent 49601e67c5
commit 8436ce1934
17 changed files with 346 additions and 0 deletions

13
test/random/float.wren Normal file
View File

@ -0,0 +1,13 @@
import "random" for Random
var random = Random.new(12345)
var below = 0
for (i in 1..1000) {
var n = random.float()
if (n < 0.5) below = below + 1
}
// Should be roughly evenly distributed.
System.print(below > 450) // expect: true
System.print(below < 550) // expect: true