examples/shuffling.asm
raw| 1 | ; |
| 2 | ; While there's no built-in shuffle function at the moment |
| 3 | ; here's an example function which can shuffle sliceable |
| 4 | ; objects like lists, strings, bytes. |
| 5 | ; |
| 6 | .seed 2021 |
| 7 | |
| 8 | shuffle .function _list |
| 9 | .for _i in random(range(len(_list), 0, -1)) |
| 10 | _list := _list[:_i] .. _list[_i+1:] .. _list[_i:_i+1] |
| 11 | .next |
| 12 | .endf _list |
| 13 | |
| 14 | .warn shuffle(['a','b','c','d','e','f','g','h']) |