fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 14: Pick uniformly a random floating point number in [a..b)
Idiom # 14: Pick uniformly a random floating point number in [a..b)
See
programming-idioms.org
:
pick(a, b f64) => a + random.next_f64 * (b-a)
What are effects?
Running Example
pick(a, b f64) => a + random.next_f64 * (b-a) for i in 1..10 a := i.as_f64 * 3 b := i.as_f64 * 4 x := pick a b do say "$x {if a <= x < b then "ok" else "not ok!"}"
What are effects?
next: Idiom # 15: Pick uniformly a random integer in [a..b]