• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

BMS Processing Class

A Course23.com Production

"Stop, Pause, and Think..." -- Ms. Elwell
"Take your time, it isn't a race" -- Mr. Helmke

  • Home
  • Graphing and Color
    • Graphing Shapes
      • Activity 1
      • Activity 2
    • Color (R,G,B) and Grey Scale
      • Activity 3
      • Activity 4
  • Code and Sketches
    • Parts of Code
      • Activity 5
    • Your Code & OpenProcessing Sketches
      • Activity 6
      • Activity 7
  • Variables, etc
    • Variables
      • Activity pre8 and 8
      • Activity 8.1
      • Activity 9
      • Activity 10
      • Activity 11
      • Activity 11.1
    • Operator Precedence
      • Activity 12
      • Activity 13
    • Random
      • Activity 14
      • Activity 15
  • Conditionals – If, Else, Else If
  • Resources

Random

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

Primary Sidebar

Required Reading:

Course Coding Standards

Copyright © 2016–2021 Chris Elwell/Michael Helmke · This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License · Log in