How to mix an array randomly. That each time a script call an array was different?

  • For some time I tried to understand the first phrase. - Oleg Arkhipov
  • 2
    "sort ... do not care" = "mix" Learn Russian, eh ?! - nikita_sergeevich
  • Everything is fine, I understand. - Oleg
  • one
    "everyone says a movie for fools, but I liked it" (c) - nikita_sergeevich

2 answers 2

This will help you a great function shuffle () , we all know how good it is, its use is a fantastic pleasure.

    Sort a large array for a long time, if the keys are consecutive - you need to generate random numbers in the range of keys and issue these items.

    • one
      Numbers are numbers from "0" to "9". You wanted to say "number" probably, not "figure." And if the keys are not consistent? And if the key is not a number, but a string? And if you do not need to produce elements, but only to form another array, will it not be even longer than the built-in function shuffle ? In general, a terrible answer that did not add anything new and useful. The correct answer about the shuffle already issued, a few years ago. - AK
    • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky
    • Too much if, with such uncertainty, there can be no right answer. With a large array with consecutive keys (if they are not consecutive - make them consistent), generating random indexes in it and issuing these elements will be faster than re-sorting it. Try to write both algorithms in a language implying working with memory - this will become obvious. Pshp hides from us this work, but will not hide the time that it should be spent on it. - Sergey