Generators

The tools library provides a set of custom data generator functions. These generator functions can be used to produce a single data or multiple data across all pinescripts basic data types - string, float, integer, unix-timestamp, boolean, color. These data can be generated as single entity or as Pinescript's arrays and matrix.

Strings

To generate random string(s), use the following functions:

Generating random string(s).

tools._rndmChar()
// returns a random a-z character.

tools._rndmCharArray()        
// returns random size array<string>, each filled with a single random a-z character.

tools._rndmCharArray(size=5)     
// returns array<string> size 5, each filled with a single random a-z character.         

tools._rndmCharMatrix()   
// returns matrix<string> with random rows and columns, each filled with single random a-z character.

tools._rndmCharMatrix(rows=3, columns=4)  
// returns 3x4 matrix<string>, each filled with a single random a-z character.

Floats

To generate random float(s), use the following functions:

Generating random float(s)

tools._rndmFloat()                                                    
// returns 66.17.

tools._rndmFloat(min=25, max=30, precision=5)                         
// returns 25.01369.

tools._rndmFloatArray()                                               
// returns random size array<float>, each filled with random floats in range 0-100 with a 
// precision of 2 decimal points.

tools._rndmFloatArray(size=3, min=0, max=1, precision=8)              
// returns array<float> size 3, each filled with random floats in range 0-1 with a precision 
// of 8 decimal points.

tools._rndmFloatMatrix()                                              
// returns matrix<float> with random rows and columns, each filled with random floats in range 
// 0-100 with a precision of 2 decimal points.

tools._rndmFloatMatrix(rows=4, columns=4, min=1, max=5, precision=1)  
// returns matrix<float> with 4 by 4 rows and columns, each filled with random floats in range 
// 1-5 with a precision of 1 decimal points.

Integers

To generate random integer(s), use the following functions:

Generating random integer(s)

tools._rndmInt()                                      
// returns 4.

tools._rndmInt(min=25, max=30)                        
// returns 27.

tools._rndmIntArray()                                 
// returns random size array<int>, each filled with random integer in range 1-100.

tools._rndmIntArray(size=3, min=-5, max=5)            
// returns array<int> size 3, each filled with random integer in range -5-5.

tools._rndmIntMatrix()                                
// returns matrix<int> with random rows and columns, each filled with random integers in 
// range 1-100.

tools._rndmIntMatrix(rows=4, columns=4, min=1, max=5) 
// returns 4x4 matrix<int>, each filled with random integers in range 1-5.

Booleans

To generate random boolean(s), use the following functions:

Generating random boolean(s)

tools._rndmBool()                         
// returns true.

tools._rndmBoolArray()                    
// returns random size array<bool>, each filled with random boolean value.

tools._rndmBoolArray(size=6)              
// returns array<bool> size 6, each filled with random boolean value.

tools._rndmBoolMatrix()                   
// returns matrix<bool> with random rows and columns, each filled with random boolean value.

tools._rndmBoolMatrix(rows=2, columns=2)  
// returns 2x2 matrix<bool>, each filled with random boolean value.

Colors

To generate random color(s), use the following functions:

Generating random color(s)

tools._rndmColor()                                    
// returns a random color (full transparency).

tools._rndmColor(trnsp=true)                          
// returns a random color with random level of transparency.

tools._rndmColorArray()                               
// returns random size array<color>, each filled with random color value 
// (full transparency).

tools._rndmColorArray(size=2, trnsp=true)             
// returns array<color> size 2, each filled with random color value and random level 
// of transparency.

tools._rndmColorMatrix()                              
// returns matrix<color> with random rows and columns, each filled with random color 
// value (full transparency) and random transparency.

tools._rndmColorMatrix(rows=3, columns=3, trnsp=true) 
// returns 3x3 matrix<color>, each filled with random color value and random level of 
// transparency.

Unix timestamps

To generate random unix-timestamp(s), use the following functions:

Generating random unix timestamp(s)

tools._rndmTimestamp()                                    
// returns 303740247000.

tools._rndmTimestamp(year=2016)                           
// returns 1470434775000.

tools._rndmTimestamp(year=2002, month=10)                 
// returns 1477449509000.

tools._rndmTimestamp(year=1998, month=02, day=12)         
// returns 887328265000.

tools._rndmTimestamp(day=12, hour=12, minute=30)          
// returns 963419451000.

tools._rndmTimestampArray()                               
// returns random size array<int>, each filled with random unix timestamp.

tools._rndmTimestampArray(size=2, year=2000, month=01)    
// returns array<int> size 2, each filled with random unix timestamp with fixed year 2000 
// and January month.

tools._rndmTimestampMatrix()                              
// returns matrix<int> with random rows and columns, each filled with random unix timestamp.

tools._rndmTimestampMatrix(rows=2, columns=2, year=1999)  
// returns 2x2 matrix<int>, each filled with random unix timestamp with fixed year 1999.