Random Number Generation

C:\Users\biyec\OneDrive\Escritorio\probability.gml
STRUCT
Canvas

Canvas widget for plotting (x,y) points.
1.0 by manta ray

Constructor syntax
Canvas(_x, _y, _w, _h)

Constructor parameters

Name Type Description Required?
_x Real x position of the canvas Yes
_y Real y position of the canvas Yes
_w Real width of the canvas Yes
_h Real height of the canvas Yes

Methods

METHOD
add_series(_series_idx)

adds a Series instance to the canvas for plotting.

Parameters

Name Type Description Required?
_series_idx Series the series instance to add Yes
Returns
   Series   self (for method chaining)
METHOD
autofit()

automatically determines the canvas x and y axes according to the data series. Note that this is automatically called at creation.

METHOD
canvas_to_x(_canvas_x)

transforms a canvas x position to a window x position

Parameters

Name Type Description Required?
_canvas_x Real the canvas x position Yes
Returns
   Real   the window x position corresponding to the provided canvas x position
METHOD
canvas_to_y(_canvas_y)

transforms a canvas y position to a window y position

Parameters

Name Type Description Required?
_canvas_y Real the canvas y position Yes
Returns
   Real   the window y position corresponding to the provided canvas y position
METHOD
clear_series()

removes all Series from the canvas Private method - won't be documented by GMLDocMaker because no method tag is specifiedrenders the canvas to the screen

Parameters

Name Type Description Required?
_redraw Bool determines whether the canvas is redrawn. No
METHOD
delete_series(_series_name)

removes a Series from the canvas

Parameters

Name Type Description Required?
_series_name String the series name Yes
METHOD
destroy()

destroys the canvas

METHOD
get_series(_series_name)

gets a Series id from the series name

Parameters

Name Type Description Required?
_series_name String the series name Yes
Returns
   Series   the series reference
METHOD
mouseover()

gets the canvas x and y positions of the mouse

Returns
   Struct   A struct of type {x, y} with the position of the canvas that is being mouseovered.
This will return {x: -1, y: -1} if the canvas is not being mouseovered.
METHOD
plot([_update=false])

plots the canvas to the screen

Parameters

Name Type Description Required?
_update String determines whether the canvas is redrawn on each call. Set to true if you need real-time updating (default), at the cost of performance, or disable it by setting this parameter to false. No
METHOD
x_to_canvas(_x)

transforms an x position to a canvas position

Parameters

Name Type Description Required?
_x Real the window x position Yes
Returns
   Real   the canvas x position corresponding to the provided x position
METHOD
y_to_canvas(_y)

transforms an y position to a canvas position

Parameters

Name Type Description Required?
_y Real the window y position Yes
Returns
   Real   the canvas y position corresponding to the provided y position

Struct return value

Returns
   Canvas   self
STRUCT
Series

Series struct that represents a collection of (x,y) points

Constructor syntax
Series(_x_array, _y_array, [_name=""], [_type=SERIES.SCATTER_PLOT])

Constructor parameters

Name Type Description Required?
_x_array Array an array of x-coordinates. Must be of the same size than _y_array. Yes
_y_array Array an array of y-coordinates. Must be of the same size than _x_array. Yes
_name String the series name. No
_type Enum the type of plot required for this series. By default, SERIES.SCATTER_PLOT No

Methods

METHOD
add_point(_x, _y)

Adds an (x,y) coordinate to this Series

Parameters

Name Type Description Required?
_x Real the x-coordinate of the point to add Yes
_y Real the y-coordinate of the point to add Yes
METHOD
save(_file)

Saves the Series data to a CSV file

Parameters

Name Type Description Required?
_file String the full file path Yes
METHOD
set_data(_x_array, _y_array)

Sets the x and y arrays

Parameters

Name Type Description Required?
_x_array Array the array of x-coordinates. Must be of the same size than _y_array. Yes
_y_array Array an array of y-coordinates. Must be of the same size than _x_array. Yes
METHOD
set_histogram_bins(_n)

Sets the number of histogram bins to n

Parameters

Name Type Description Required?
_n Real the number of bins Yes

Struct return value

Returns
   Series   self
FUNCTION
Binomial

Generates a Binomial random variable.

Syntax
Binomial(_k, _n, _p)

Parameters

Name Type Description Required?
_k Real The number of successes. Must be integer. Yes
_n Real The number of trials. Must be integer. Yes
_p Real The probability of success of a single trial. Yes
Returns
   Real   The Binomial random variable.
FUNCTION
Box_Muller

Generates a Normal random variable with given mu and sigma, using the Box-Muller transformation.

Syntax
Box_Muller([_mu=0], [_sigma=1])

Parameters

Name Type Description Required?
_mu Real Mean of the distribution, by default 0. No
_sigma Real Standard deviation of the distribution, by default 1. No
Returns
   Real   The Normal random variable. For more information, please see this Wikipedia article.
FUNCTION
Exponential

Generates an exponential random variable with a given beta parameter, using the inverted CDF technique.

Syntax
Exponential(_beta)

Parameters

Name Type Description Required?
_beta Real The beta parameter. Must be greater than 0. See Wikipedia for reference. Yes
Returns
   Real   A random number from the exponential distribution.
FUNCTION
Normal

Evaluates the Normal distribution function at _x, with mean _mu and standard deviation _sigma.

Syntax
Normal(_x, _mu, _sigma)

Parameters

Name Type Description Required?
_x Real The value of x. Yes
_mu Real Mean of the distribution. Yes
_sigma Real Standard deviation of the distribution. Yes
Returns
   Real   The value of the distribution function at x.
FUNCTION
Poisson

Generates a Poisson random variable with given lambda parameter.

Syntax
Poisson(_lambda, [_return_array=false])

Parameters

Name Type Description Required?
_lambda Real The lambda parameter, the rate of arrival. Must be greater than 0. See Wikipedia for reference. Yes
_return_array Bool Optional boolean parameter. If true, returns the array of arrival times instead. If false, returns the Poisson variate. No
Returns
   Any   Poisson variate (Integer) or an array of arrival times (Array)
FUNCTION
array_random

selects an index from the array with the specified probabilities

Syntax
array_random(array=[], probabilities=[], return_index=false)

Parameters

Name Type Description Required?
_array Array the array that holds the values to select from.
if not provided, it will create a consecutive integer array, starting with 1, up to the size of the _probabilities array.
if the _probabilities array is also not provided, it will simply return a 0 or 1 random variable (Bernoulli)
No
_probabilities Array the array that holds the corresponding probabilities. Should add up to 1 - if not, the function will normalize them.
if not provided, it will create a uniform probability array matching the size of the _probabilities array.
if the _array array is also not provided, it will simply return a 0 or 1 random variable (Bernoulli)
No
_return_index Bool if true it will return the selected index; if false (default) it will return the corresponding value from _array. No
Returns
   Any   the randomly selected item or index