Documented shuffle from random module (#5204)
This commit is contained in:
parent
c98a8f3701
commit
17c62bb545
1 changed files with 1 additions and 0 deletions
|
|
@ -107,6 +107,7 @@ proc randomize*(seed: int) {.benign.} =
|
|||
state.a1 = ui(seed and 0xffff)
|
||||
|
||||
proc shuffle*[T](x: var seq[T]) =
|
||||
## Will randomly swap the positions of elements in a sequence.
|
||||
for i in countdown(x.high, 0):
|
||||
let j = random(i + 1)
|
||||
swap(x[i], x[j])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue