fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 15: Pick uniformly a random integer in [a..b]
Idiom # 15: Pick uniformly a random integer in [a..b]
See
programming-idioms.org
:
Code
pick(a, b i32) => a + random.next_i32 b-a+1
What are effects?
Running Example
pick(a, b i32) => a + random.next_i32 b-a+1 for i in 1..10 a := i * 3 b := i * 4 x := pick a b do say "$x {if a <= x <= b then "ok" else "not ok!"}"
What are effects?
last changed: 2024-07-01
next: Idiom # 16: Depth-first traversing of a binary tree