User Tools

Site Tools


crpl:docs:randint

Differences

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

Link to this comparison view

Next revision
Previous revision
crpl:docs:randint [2013/01/14 14:06] – created chanicrpl:docs:randint [2020/05/28 05:42] (current) WithersChat
Line 1: Line 1:
-TODO+<- [[crpl:crplreference|CRPL reference]] <- [[crpl:crplreference#utility_commands|Utility Commands]] 
 +=====  RandInt  ===== 
 + 
 +^Arguments^Result^Notation^ 
 +|A, B|Random Integer |''n1 n2 -- n3 ''
 + 
 + 
 +=== Description === 
 +//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 ''B < 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. 
 + 
 +=== Examples === 
 +<code> 
 +#Creates a dancing number readout. Very high tech hackery. 
 +0 10 RandInt 
 +0 10 RandInt concat 
 +0 10 RandInt concat 
 +0 10 RandInt concat 
 +SetPopupText 
 +     
 +:awake 
 +  TRUE OperateWhilePaused 
 +</code>  
 + 
 +<code> 
 +# Showcases the difference between passing (Low, High) or (High, Low) into the function. 
 +once 
 +    ClearTraceLog 
 +    ShowTraceLog 
 +    50 0 do  
 +        #        A    B                      results         logic 
 +        "lohi " -2    2   RandInt " "     #  -2 -1 0 1       A <= RandInt < B 
 +        "hilo "  2   -2   RandInt Trace5  #     -1 0 1 2     B < RandInt <= A 
 +    loop 
 +endonce 
 +</code>  
 + 
crpl/docs/randint.1358190411.txt.gz · Last modified: 2014/10/01 15:02 (external edit)