1 | // returns selected, rest |
2 | static <A> Pair<L<A>> selectRandom2(L<A> list, int n) { |
3 | if (l(list) < n) null; |
4 | new L<A> l; |
5 | list = cloneList(list); |
6 | repeat n { |
7 | int i = rand(l(list)); |
8 | l.add(list.get(i)); |
9 | list.remove(i); |
10 | } |
11 | ret pair(l, list); |
12 | } |
Began life as a copy of #1002448
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1008665 |
Snippet name: | selectRandom2 - select n random elements from list (in random order, no duplicates), return rest list also |
Eternal ID of this version: | #1008665/4 |
Text MD5: | 0eebaab529fa17dd815074c1b3695728 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-05-27 14:03:47 |
Source code size: | 268 bytes / 12 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 512 / 539 |
Version history: | 3 change(s) |
Referenced in: | [show references] |