Random Block

The Random block can output a random Numeric or Logic value. You can use the result of the Random block to make your robot randomly choose from different actions.
Choose the Output Type
Mode Selector
Inputs
Output
Use the Mode Selector to choose whether to output a random Numeric value or a random Logic value. After selecting the mode, you can choose the Inputs. The inputs control the range and probability of the Value output.
Modes
Numeric


The Numeric mode outputs a random integer value. The Value will be set to a random integer that is within the range specified by the Lower Bound and Upper Bound. Each integer value within this range is equally likely to be chosen.
Example
This program makes a continuous series of tones of random frequencies in the range of 500 to 5000 Hz.
Logic


The Logic mode outputs a True or False value. The probability that a True value will be output is specified by the Probability of True input. This input is a percentage value from 0 to 100. For example, a probability of 25 would result in a 25% chance that True is output and a 75% chance that False is output.
Example
This program makes the robot choose randomly between turning left and turning right, with a 50/50 chance of each.
Tips and Tricks
To make your robot choose from more than two actions at random, you can use a Random Block with the Numeric mode and a Switch Block in the Numeric mode. For example, you could output a random number from 1 to 5 and use this value to choose from five different cases in the Switch.
Inputs and Outputs
The inputs of the Random block control the range and probability of the output value. You can enter the input values directly into the block. Alternatively, the values can be supplied by Data Wires from the outputs of other Programming Blocks.
InputTypeAllowed ValuesNotes
Lower Bounds NumericAny NumberLower bound for Numeric output
Upper Bounds NumericAny NumberUpper bound for Numeric output
Probability of True Numeric0 to 100Percentage probability of True result for Logic output
The output of the Random block gives the random value. To use the output, use a Data Wire to connect it to another Programming Block.
OutputTypeNotes
Value Numeric or LogicNumeric in Numeric mode
Logic in Logic mode
Random
Quick links