tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
17
Task/Random-numbers/Fantom/random-numbers-1.fantom
Normal file
17
Task/Random-numbers/Fantom/random-numbers-1.fantom
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class Main
|
||||
{
|
||||
static const Float PI := 0.0f.acos * 2 // we need to precompute PI
|
||||
|
||||
static Float randomNormal ()
|
||||
{
|
||||
return (Float.random * PI * 2).cos * (Float.random.log * -2).sqrt
|
||||
}
|
||||
|
||||
public static Void main ()
|
||||
{
|
||||
mean := 1.0f
|
||||
sd := 0.5f
|
||||
Float[] values := [,] // this is the collection to fill with random numbers
|
||||
1000.times { values.add (randomNormal * sd + mean) }
|
||||
}
|
||||
}
|
||||
20
Task/Random-numbers/Fantom/random-numbers-2.fantom
Normal file
20
Task/Random-numbers/Fantom/random-numbers-2.fantom
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using [java] java.util::Random
|
||||
|
||||
class Main
|
||||
{
|
||||
Random generator := Random()
|
||||
|
||||
Float randomNormal ()
|
||||
{
|
||||
return generator.nextGaussian
|
||||
}
|
||||
|
||||
public static Void main ()
|
||||
{
|
||||
rnd := Main() // create an instance of Main class, which holds the generator
|
||||
mean := 1.0f
|
||||
sd := 0.5f
|
||||
Float[] values := [,] // this is the collection to fill with random numbers
|
||||
1000.times { values.add (rnd.randomNormal * sd + mean) }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue