Random shuffles with JavaScript Arrays
This article mainly introduces how to implement the random shuffling function by random arrangement of JavaScript arrays, involving list-based javascript. the sort method can be used for random shuffling to realize random array arrangement. It is very useful. For more information, see
This article describes how to randomly shuffles JavaScript arrays. Share it with you for your reference. The specific analysis is as follows:
This JS code can be used to randomly arrange the elements in the group. This is very useful. For example, we can arrange cards when playing cards, that is, shuffling computers.
?
| 1 2 3 |
Var list = [1, 2, 3, 4, 5, 6, 7, 8, 9]; List = list. sort (function () Math. random ()-0.5 ); Print (list); // prints something like:, 8 |
I hope this article will help you design javascript programs.