How to randomize subset of array in Javascript?

后端 未结 4 1539
死守一世寂寞
死守一世寂寞 2021-01-25 18:22

What is the best way to randomize part of the array in Javascript

For example, if I have 100 items in the array, what is the fast and efficient way of randomizing set of

4条回答
  •  爱一瞬间的悲伤
    2021-01-25 19:01

    You can adjust the array shuffle method that is described here: http://jsfromhell.com/array/shuffle

    It is based on Fisher-Yates (Knuth) algorithm (http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).

提交回复
热议问题