mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 21:17:48 +00:00
Documented shuffle from random module (#5204)
This commit is contained in:
committed by
Andreas Rumpf
parent
c98a8f3701
commit
17c62bb545
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user