Using Random Numbers
The randomNumber()
block can be used to generate random numbers in your programs. The parameters set the minimum and maximum value that could be generated. You can use this block anywhere that you could write a number.
This example is like a die that could randomly generate any number from 1 to 6
Drawing and Random Numbers
You can use randomNumber()
as a parameter in drawing commands to make random drawings. With the following command, your program might generate different drawings each time it's run.
Run 1 | Run 2 | Run 3 |
---|---|---|
![]() | ![]() | ![]() |
Multiple Random Numbers
If you use randomNumber()
multiple times in your program it will generate new random numbers every time. You can think of each randomNumber()
like a new roll of a die.
Run 1 | Run 2 | Run 3 |
---|---|---|
![]() | ![]() | ![]() |
Found a bug in the documentation? Let us know at support@code.org.
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.