julia shuffle vector

Solutions on MaxInterview for julia shuffle vector by the best coders in the world

showing results for - "julia shuffle vector"
Lucas
23 Jul 2018
1### Julia ###
2
3using Random: shuffle, shuffle!
4
5v = [1, 2, 3, 4, 5, 6]
6
7println(v)
8# [1, 2, 3, 4, 5, 6]
9
10# Create a shuffled vector from `v`, leaving `v` as is.
11shuffled_v = shuffle(v)
12println(shuffled_v)
13# [6, 4, 1, 2, 3, 5]
14println(v)
15# [1, 2, 3, 4, 5, 6]
16
17# Shuffle `v` in place
18shuffle!(v)
19println(v)
20# [3, 4, 2, 6, 5, 1]