1 | static <A> A randomFromIterator(int n, Iterator<A> it) {
|
2 | n = random(n); |
3 | while (n-- > 0) |
4 | if (it.hasNext()) it.next(); else null; |
5 | ret it.hasNext() ? it.next() : null; |
6 | } |
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: | #1013017 |
| Snippet name: | randomFromIterator - can return null if n is not correct |
| Eternal ID of this version: | #1013017/1 |
| Text MD5: | 87d2c48b197f13f84f4bb51f4be82fca |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2017-12-21 03:37:17 |
| Source code size: | 181 bytes / 6 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 720 / 730 |
| Referenced in: | [show references] |