EZ Math Movie, Tutorials, Mathematics, Random Numbers


Random coordinates

We look at two commands, randomX and randomY. Each returns, or outputs, a random x- or y-coordinate respectively. So this program line:

x = randomX();

Places a value into the variable x that is between worldXMin and worldXMax. Actually, x could contain the value of worldXMin up to but not including worldXMax. If the x-axis had its bounds set up to be from -10 to 10, then x could contain values from -10 to 9.9999....

The command randomY works the same way, except it returns values relative to the y-axis.

If you change the bounds of the graph, these two functions will appropriately change the way they return values.

Note that these commands are different than many that we have seen. These return meaningful values. The command drawLineSegment, for example, does not return any meaningful value that would be placed in a variable.

Be sure to note the necessary parentheses when using randomX and randomY.

Ranges of random numbers

You can also create random numbers over any range. The randomRealRange command is used for this:

randomRealRange(minimum, maximum);

So, if you wanted to generate a random number somewhere between 2 and 4, then this program line would place that value into the variable a:

a = randomRealRange(2, 4);

Actually, the above program line will place a random value into a over a range from and including 2 up to but not including 4. That is, the range would be 2 to 3.9999....

This will work with negative and positive numbers, just as long as the first value is less than the second value.

Running the example program

This program is showing two basic procedures:

This is our first animating EZ Math Movie. You will need to click the 'Stop' button to halt this program.

Also, note that this program has some code in the before loop section. Usually, as here, when a program is the animating type, all setup code goes in the before loop section. We really do not want to clear the graph and printer at the start of each loop cycle. We want to do those things once in the before loop section, and then let the points pile up on the graph and the numbers scroll down the printer.

Understand that these are not related procedures. The points on the scattering around the graph have no connection to the numbers pouring out of the printer. The program is just showing two ways that EZ Math Movie makes random numbers.

Don't forget to press 'Stop', or the program will run endlessly.


The example program

0ptions
Angle measurement: Degrees Radians

Go on input

Bounds:
Sorry, apparently this browser does not support HTML 5 canvas tag graphics.
Printer

Edit: Runtime          View: Starter Suggestion

To runtime:

Storage:

Editor width: Normal Wide


		

	


		

	


		

	

And....

Next tutorial: Powers, square roots

 

Here are some links to related articles at EZ Programing Demos:

About functions

Random

Random over range


All contents of EZ Math Movie are copyrighted: Copyright 2011, Edward A. Zobel. All rights reserved.



Other sites you may find interesting

Zona Land Education Like Math and Physics?

Zona Land Education offers explanations, diagrams, and animations on these topics.
And it is all presented in a clear and casual manner.

Here is the link: zonalandeducation.com




EZ Programing Demos Want to learn about programing computers?

EZ Programing Demos has an animated, slow motion, interactive programing language demonstrator.
The site presents basic ideas at a beginner's level.

Here is the link: ezprogramingdemos.com



Custom Search

Name:
Domain:

Name
0


Name:
Name
0