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

13
LINES

< > BotCompany Repo | #1001295 // oneOf function

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7877L/44K).

1  
static <A> A oneOf(L<A> l) {
2  
  if (empty(l)) null;
3  
  int n = l.size();
4  
  ret n == 1 ? first(l) : l.get(defaultRandomizer().nextInt(n));
5  
}
6  
7  
static char oneOf(S s) {
8  
  ret empty(s) ? '?' : s.charAt(random(l(s)));
9  
}
10  
11  
static <A> A oneOf(A... l) {
12  
  ret oneOf(asList(l));
13  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001295
Snippet name: oneOf function
Eternal ID of this version: #1001295/6
Text MD5: 7ba2a1b46b685dd49395c04c5a60702b
Transpilation MD5: c2aa05f8043098f8aa0aa90246dfce19
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-02 20:33:45
Source code size: 280 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 760 / 1203
Version history: 5 change(s)
Referenced in: [show references]