This documentation explains basic math operations, including addition, subtraction, multiplication, division, setting and converting numbers, finding remainders, minimum and maximum values, absolute values, square roots, approximations, and generating random values.
Adding/Subtracting/Multiplying Two Values
0 + 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_arithmetic\"><field name=\"OP\">ADD</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This is used to return the sum of two numbers.
Parameters: Condition:
- Number (Default: 0)
- Operator: + (Default)/-/×/÷/**
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>add</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">add</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">ADD</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">add</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Dividing two numbers
0 ÷ 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_arithmetic\"><field name=\"OP\">DIVIDE</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to return the quotient between two numbers.
Parameters: Condition:
- Number (Default: 0)
- Operator: + (Default)/-/×/÷/**
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>divide</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">divide</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">DIVIDE</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">divide</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
When it is count ÷ 2, the output:
When it is count ** 2, the output:
Setting a Number
0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_number\"><field name=\"NUM\">0</field></block></xml>"}
This block is used to set the value to number or decimal number.
Parameters: Condition: Number (Default: 0)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">6.1</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Showing Remainder Between Two Numbers
Reminder of 0 ÷ 1
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_modulo\"><value name=\"DIVIDEND\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"DIVISOR\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></xml>"}
This block is used to show the remainder between two values.
Parameters: Condition: Number (Default: 0)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>remainder</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">remainder</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_modulo\"><value name=\"DIVIDEND\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"DIVISOR\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">remainder</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Finding the Minimum Values
minimum of 0 and 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_op2\"><field name=\"op\">min</field><value name=\"x\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"y\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
The “minimum of 0 and 0” block is used to extract the smaller one between two numbers.
Parameters: Condition: Number (Default: 0)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>minimum</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">minimum</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_op2\"><field name=\"op\">min</field><value name=\"x\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"y\"><shadow type=\"math_number\"><field name=\"NUM\">4</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">minimum</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Finding the Maximum Values
Max of 0 and 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_op2\"><field name=\"op\">max</field><value name=\"x\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"y\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to take the larger value between two numbers.
Parameters: Condition: Number (Default: 0)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>count</variable><variable>maximum</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">3.568</field></shadow></value><next><block type=\"variables_set\"><field name=\"VAR\">maximum</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_op2\"><field name=\"op\">max</field><value name=\"x\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"y\"><shadow type=\"math_number\"><field name=\"NUM\">4</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">maximum</field></block></value></block></value></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Changing the Number to Absolute Value
Absolute of 0
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_op3\"><value name=\"x\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to make the value of the number to absolute value.
Parameters: Condition: Number (Default: 0)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>absolute</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">absolute</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_op3\"><value name=\"x\"><shadow type=\"math_number\"><field name=\"NUM\">-10</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">absolute</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Taking the Square Root
Square root
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_js_op\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" op-type=\"unary\"></mutation><field name=\"OP\">sqrt</field><value name=\"ARG0\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to take the square root of the value.
Parameters: Condition:
- Number (Default: 0)
- Square root (Default)/sin/cos/tan/atan2/integer ÷/integer ×
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>value</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">value</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_js_op\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" op-type=\"unary\"></mutation><field name=\"OP\">sqrt</field><value name=\"ARG0\"><shadow type=\"math_number\"><field name=\"NUM\">144</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
When it sets to square root 144, the output:
When it sets to sin 144, the output:
When it sets to cos 144, the output:
When it sets to tan 144, the output:
When it sets to atan2 144 0, the output:
When it sets to 144 integer ÷ 5, the output:
When it sets to 144 integer × 5, the output:
Converting the Number to an Approximate Value
Round
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"math_js_round\"><field name=\"OP\">round</field><value name=\"ARG0\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
This block is used to replace the number with an approximate value. If the fractional part is more than one half, the number will increase.
Parameters: Condition:
- Number (Default: 0)
- Round (Default)/ceiling/floor/truncate
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>value</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">value</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_js_round\"><field name=\"OP\">round</field><value name=\"ARG0\"><shadow type=\"math_number\"><field name=\"NUM\">5.11</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
When it sets to round 5.11, the output:
When it sets to ceiling 5.11, the output:
When it sets to floor 5.99, the output:
When it sets to truncate 5.99, the output:
Choosing the Random Value
Pick Random 0 to 10
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"device_random\"><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"limit\"><shadow type=\"math_number\"><field name=\"NUM\">10</field></shadow></value></block></xml>"}
This block is used to choose the random number between the range.
Parameters: Condition: Number (Default: 0 and 10)
Output: Number
Sample code:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>value</variable><variable>dateTimeOffset</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">value</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"device_random\"><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"limit\"><shadow type=\"math_number\"><field name=\"NUM\">10</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"DateTime_DateTimeOffset_toString\"><value name=\"dateTimeOffset\"><block type=\"variables_get\"><field name=\"VAR\">value</field></block></value></block></value></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
The output:
Table of Content