User Tools

Site Tools


crpl:docs:randint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
crpl:docs:randint [2020/05/26 18:23] – Added a Note and example for special cases Saniancrpl:docs:randint [2020/05/28 05:42] (current) WithersChat
Line 3: Line 3:
  
 ^Arguments^Result^Notation^ ^Arguments^Result^Notation^
-|MinMax|Random Integer |''n1 n2 -- n2 ''|+|AB|Random Integer |''n1 n2 -- n3 ''|
  
  
 === Description === === Description ===
-Pops Min and Max from the stack and pushes a random integer to stack where ''min <RandInt < max''+//Pops A and B from the stack and pushes a random integer to the stack that can be any value from A up to, but not including, B.// 
 + 
 +**In the case that ''A < B'':**  
 + 
 +Pops A and B from the stack and pushes a random integer to stack where ''A <= RandInt < B''. In this case A and B may be treated as Min and Max similar to how many other languages treat random functions. For consistent results it is best to make sure that your input is always structured like this. 
 + 
 + 
 +**In the case that ''A > B'':**  
 + 
 +Pops A and B from the stack and pushes a random integer to stack where ''< RandInt <= A''.  
 + 
 + 
 +**In the case that ''A == B'':**  
 + 
 +Pops A and B from the stack and pushes back a single integer equal to A and B. Example: ''RandInt(1, 1)'' will always return 1.
  
-**Note:** Min may be higher than Max, however the resulting value will follow a different rule where ''min >= RandInt > max'' 
 === Examples === === Examples ===
 <code> <code>
Line 29: Line 42:
     ShowTraceLog     ShowTraceLog
     50 0 do      50 0 do 
-        #       min  max                     results         logic +        #           B                      results         logic 
-        "lohi " -2    2   RandInt " "     #  -2 -1 0 1       min <= RandInt < max +        "lohi " -2    2   RandInt " "     #  -2 -1 0 1       <= RandInt < B 
-        "hilo "  2   -2   RandInt Trace5  #     -1 0 1 2     min >= RandInt > max+        "hilo "  2   -2   RandInt Trace5  #     -1 0 1 2     B < RandInt <= A
     loop     loop
 endonce endonce
crpl/docs/randint.txt · Last modified: 2020/05/28 05:42 by WithersChat