Random iteration in Julia Programming

142 Views Asked by At

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).

1

There are 1 best solutions below

0
Bill On BEST ANSWER
using Random

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