juliaijulia-notebook

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


Solution

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