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

15
LINES

< > BotCompany Repo | #1018802 // varyIntRange

JavaX fragment (include)

static IntRange varyIntRange(IntRange r, int variation, int minLength, int min, int max) {
  // vary start within min/max
  int start = random(max(min, r.start-variation), min(max, r.start+variation)+1);
  // vary end within .../max
  int end = random(r.end-variation, min(max, r.end+variation+1));
  // make longer if too short
  end = max(end, start+minLength);
  // move left if too long
  if (end > max) {
    int shift = end-max;
    start -= shift;
    end -= shift;
  }
  ret intRange(start, end);
}

Author comment

Began life as a copy of #1018801

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018802
Snippet name: varyIntRange
Eternal ID of this version: #1018802/1
Text MD5: a9ddc411d9b0a1d1a6224f023a8e7cf1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-13 19:56:25
Source code size: 520 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 282 / 301
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)