How can I take n elements at random from a Perl array?

后端 未结 4 1265
半阙折子戏
半阙折子戏 2020-12-14 12:10

I have an array, A = [a1,a2,a3,...aP] with size P. I have to sample q elements from array A.

I plan to use a loop with q

4条回答
  •  半阙折子戏
    2020-12-14 12:17

    You may construct second array, boolean with size P and store true for picked numbers. And when the numer is picked, check second table; in case "true" you must pick next one.

提交回复
热议问题