Answers for "julia shuffle vector"

0

julia shuffle vector

### Julia ###

using Random: shuffle, shuffle!

v = [1, 2, 3, 4, 5, 6]

println(v)
# [1, 2, 3, 4, 5, 6]

# Create a shuffled vector from `v`, leaving `v` as is.
shuffled_v = shuffle(v)
println(shuffled_v)
# [6, 4, 1, 2, 3, 5]
println(v)
# [1, 2, 3, 4, 5, 6]

# Shuffle `v` in place
shuffle!(v)
println(v)
# [3, 4, 2, 6, 5, 1]
Posted by: Guest on June-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language