# Random Module

This module contains a set of functions for generating and sampling random data.

### =RANDBETWEENS(startOrEndNumberArray)

This function is similar to RANDBETWEEN, except that it allows multiple ranges from which to pick a random number. One of the ranges from which to generate a random number between is chosen at an equal probably.

#### Arguments

Variant: startOrEndNumberArray() --->

#### Returns

Variant: Returns either TRUE or FALSE based on the random value choosen

###### Note

This function always requires an even number of inputs. Essentially, when using multiple numbers, the 1st and 2nd will make up a range from which to pull a random number between, the 3rd and 4th will make a different range, and so on. If an even number is used, this function will return a User-Defined Error. See the ISERRORALL() function for how to handle these numbers.#### Examples

- =RANDBETWEENS(1, 10, 5000, 5010) -> 6
- =RANDBETWEENS(1, 10, 5000, 5010) -> 5002
- =RANDBETWEENS(1, 10, 5000, 5010) -> 8
- =RANDBETWEENS(1, 10, 5000, 5010) -> 3
- =RANDBETWEENS(1, 10, 5000, 5010) -> 5010
- =RANDBETWEENS(1, 10, 5000, 5010) -> 2
- =RANDBETWEENS(5, 10, 15, 20, 25, 30, 35, 40) -> 32

### =RANDBOOL()

This function generates a random Boolean (TRUE or FALSE) value

#### Arguments

None

#### Returns

Boolean: Returns either TRUE or FALSE based on the random value choosen

#### Examples

- =RANDBOOL() -> TRUE
- =RANDBOOL() -> FALSE
- =RANDBOOL() -> TRUE
- =RANDBOOL() -> TRUE
- =RANDBOOL() -> FALSE
- =RANDBOOL() -> FALSE

### =RANDOM_RANGE(startNumber, stopNumber, stepNumber)

This function takes 3 numbers, a start number, a stop number, and a step number, and returns a random number between the start number and stop number that is an interval of the step number.

#### Arguments

Integer: startNumber ---> is the beginning value of the range

Integer: stopNumber ---> is the end value of the range

Integer: stepNumber ---> is the step of the range

#### Returns

Integer: Returns a random number between the start and stop that is a multiple of the step

#### Examples

- =RANDOM_RANGE(50, 100, 10) -> 60
- =RANDOM_RANGE(50, 100, 10) -> 50
- =RANDOM_RANGE(50, 100, 10) -> 90
- =RANDOM_RANGE(0, 10, 2) -> 8
- =RANDOM_RANGE(0, 10, 2) -> 0
- =RANDOM_RANGE(0, 10, 2) -> 4
- =RANDOM_RANGE(0, 10, 2) -> 10

### =RANDOM_SAMPLE(rangeArray)

This function takes an array of cells and returns a random value from the cells chosen

#### Arguments

Range: rangeArray ---> a single cell or multiple cells where the sample will be pulled from

#### Returns

Variant: Returns a random cell value from the array of cells chosen

#### Examples

- =RANDOM_SAMPLE(A1:A5) -> "Hello"; where "Hello" is the value in cell A3, and where A3 was the chosen random cell
- =RANDOM_SAMPLE(A1:A5) -> "World"; where "World" is the value in cell A2, and where A2 was the chosen random cell

### =RANDOM_SAMPLE_PERCENT(valueRange, percentRange)

This function takes 2 ranges, one with values that will be sampled, and the other with the percentage chance that the value will be sampled, and returns a value from the sample.

#### Arguments

Range: valueRange ---> is the range containing values of which one will be sampled

Range: percentRange ---> is the range that contains the percent chances of the values in the valueRange

#### Returns

Variant: Returns a random value from the valueRange

###### Warning!

Internally this function sums up all the number in the percentRange to calculate percentage chances of a sample. For example, if the percentRange contains the values 10 and 90, the first value will have a 10/(10+90) = 10% chance of being chosen. Similarly, if the values in the percentRange contains the values 5 and 45, the first value will have a 5/(5+45) = 10% chance of being chosen. This means you have to be careful when choosing percentages in the percentRange, as if you choose 0.1 and 0.8 for the percentRange, the percentage chance the first value is chosen is NOT 10%, but rather 0.1/(0.1+0.8) = 11.1%. Thus, you should be careful to only interpret a 0.1 in the percentRange as a 10% chance only if the values in the percentRange actually sum up to 1.0.#### Examples

- =RANDOM_SAMPLE_PERCENT(A1:A2, B1:B2) -> "Hello"; Assuming the valueRange contains ["Hello", "World"], and percentRange contains [.9, .1]
- =RANDOM_SAMPLE_PERCENT(A1:A2, B1:B2) -> "Hello"; Assuming the valueRange contains ["Hello", "World"], and percentRange contains [.9, .1]
- =RANDOM_SAMPLE_PERCENT(A1:A2, B1:B2) -> "Hello"; Assuming the valueRange contains ["Hello", "World"], and percentRange contains [.9, .1]
- =RANDOM_SAMPLE_PERCENT(A1:A2, B1:B2) -> "World"; Assuming the valueRange contains ["Hello", "World"], and percentRange contains [.9, .1]; Notice how "World" shows up less since there is only a 10% chance it is chosen.