Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

7
LINES

< > BotCompany Repo | #1002448 // selectRandom - select n random elements from list (in random order, no duplicates), synonym of selectRandom_fast

JavaX fragment (include)

static <A> L<A> selectRandom(int n, L<A> list) {
  ret selectRandom(list, n);
}

static <A> L<A> selectRandom(L<A> list, int n) {
  ret selectRandom_fast(list, n);
}

Author comment

returns less than n elements if list too small

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: #1002448
Snippet name: selectRandom - select n random elements from list (in random order, no duplicates), synonym of selectRandom_fast
Eternal ID of this version: #1002448/6
Text MD5: 25369e10ec6200be67c86b6790a46af2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-22 17:19:00
Source code size: 171 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 661 / 613
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1007376 - selectRandomPair - select a random pair from a list
#1007571 - selectRandomUpTo - select up to n random elements from list (in random order, no duplicates)
#1008665 - selectRandom2 - select n random elements from list (in random order, no duplicates), return rest list also
#1014026 - selectRandomWithMultiples - select n random elements from list (in random order, with duplicates)
#3000382 - Answer for ferdie (>> t = 1, f = 0)