Random is a special type of Function that returns a value.
For example:
- Me: Hey random, what’s going on? Hope you’re well. Hey, I was wondering… could you give me a random number between 1 and 100?
- Random: Sure, no problem. How about the number 63?
- Me: Awesome! That’s great, thank you.
In code, this would look like:
1 2 |
var w = random(1, 100); rect(100, 100, w, 50); |
The random() function requires two arguments. It returns a random number ranging from the first argument to the second argument. The second argument must be larger than the first argument for it to work properly. The function random() also works with one argument by assuming a range between ZERO and that argument, such as random(6)
which will return a random number between 0 and 6.
Complete Activity 14
Complete Activity 15