1

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

Gua
  • 33
  • 5
  • https://stackoverflow.com/questions/60557139/how-can-i-shuffle-a-range-of-numbers-and-then-split-it-into-subarrays-of-a-certa – chiliNUT Oct 13 '22 at 22:15
  • Does this answer your question? [How can I shuffle a range of numbers and then split it into subarrays of a certain length?](https://stackoverflow.com/questions/60557139/how-can-i-shuffle-a-range-of-numbers-and-then-split-it-into-subarrays-of-a-certa) – anarchy Oct 13 '22 at 22:22

1 Answers1

5
using Random

for i in shuffle(1:N)
   # do something with i
end
Bill
  • 5,600
  • 15
  • 27