Gua
Gua

Reputation: 33

Random iteration in Julia Programming

When you want to iterate sequentially over a list of numbers from 1 to N in Julia you will write:

for i in 1:N
   # do something with i
end

But what if you want to iterate over the list of numbers from the range (1...N) randomly? There is a need in every iteration to randomly choose the number that wasn't chosen in any previous iteration and there is a need to iterate over all of the numbers from the range (1...N).

Upvotes: 1

Views: 202

Answers (1)

Bill
Bill

Reputation: 6086

using Random

for i in shuffle(1:N)
   # do something with i
end

Upvotes: 5

Related Questions