fuzion-lang.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, seq Sequence T) => if seq.count < 2 then seq else (l,t) := seq.split_at (random.next_i32 seq.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, seq Sequence T) => if seq.count < 2 then seq else (l,t) := seq.split_at (random.next_i32 seq.count) (m,r) := t.split_at 1 m ++ shuffle l++r say (shuffle x)
What are effects?
last changed: 2024-07-01
next: Idiom # 11: Pick a random element from a list