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

18
LINES

< > BotCompany Repo | #1033154 // runProbabilisticForNSeconds

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

Libraryless. Click here for Pure Java version (4910L/28K).

1  
svoid runProbabilisticForNSeconds(double seconds, IProbabilistic p) {
2  
  if (p == null) ret;
3  
  p.run();
4  
  runProbabilisticForNSeconds(seconds, p.scheduler());
5  
}
6  
7  
svoid runProbabilisticForNSeconds(double seconds, IProbabilisticScheduler ps) {
8  
  if (ps == null) ret;
9  
  Timeout timeout = new(seconds);
10  
  long steps = 0;
11  
  while (!timeout.reached()) {
12  
    ++steps;
13  
    if (!ps.step())
14  
      break;
15  
  }
16  
  
17  
  print(nSteps(steps) + " in " + formatDouble(timeout.elapsedSeconds(), 1) + " s, reached probability " + ps.lastExecutedProbability());
18  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033154
Snippet name: runProbabilisticForNSeconds
Eternal ID of this version: #1033154/6
Text MD5: 00918c12b1c983d9f7ab1cea18882634
Transpilation MD5: b90cd802a1ed52b7d1ae55e03fe89978
Author: stefan
Category: javax / probabilistic scheduling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-15 19:55:24
Source code size: 555 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 157 / 226
Version history: 5 change(s)
Referenced in: [show references]