flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 10: Shuffle a list
Idiom # 10: Shuffle a list
See
programming-idioms.org
:
Code
shuffle(T type, x Sequence T) => if x.count < 2 then x else (l,t) := x.split_at (random.next_i32 x.count) (m,r) := t.split_at 1 m ++ shuffle l++r
What are effects?
Running Example
x := [1,2,3,4,5,6,7,8,9,10] shuffle(T type, x Sequence T) => if x.count < 2 then x else (l,t) := x.split_at (random.next_i32 x.count) (m,r) := t.split_at 1 m ++ shuffle l++r say (shuffle x)
What are effects?
next: Idiom # 11: Pick a random element from a list