50 random unique elements from an array of 1000 elemens?

前端 未结 7 854
忘掉有多难
忘掉有多难 2020-12-21 01:22

What is the simplest way to get 50 random unique elements from an array of 1000 elements ?

text = new Array();
for(i=0;i<1000;i++){ text[i]=i; }   //array         


        
相关标签:
7条回答
  • 2020-12-21 02:11

    Look into the Fisher-Yates algorithm, I think this will work for you.

    0 讨论(0)
提交回复
热议问题