Merge: Functional api
[nit.git] / examples / rosettacode / random_numbers.nit
1 #!/usr/bin/env nit
2 #
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
5
6 # Task: Random numbers
7 #
8 # See: <http://rosettacode.org/wiki/Random_numbers>
9 module random_numbers
10
11 # Uniform distribution, (0..1]
12 fun drand: Float do return 1.0.rand
13
14 # Pseudorandom numbers with a mean of 1.0 and a standard deviation of 0.5
15 fun random_normal: Float do return (-2.0 * drand.log).sqrt * (2.0 * pi * drand).cos
16
17 for i in [0..1000] do print random_normal