|
At the beginning of this quarter, we looked at a special object called Math. As we have seen, this object has useful attributes like PI, and E and functions (methods) like abs, sin, and sqrt. Another useful Math object function is the random() function. This function returns a randomly selected real number between 0.0 and 1.0. This means that the expression Math.random() is replaced by a decimal value. The following code will place a randomly selected value in a text box as shown below. Many programs require the use of "random" numbers other than decimal values between 0 and 1. Using our mathematics knowledge, we can write expressions that generate random numbers in other useful forms. Let us begin by generating random integers. By multiplying the random real values by 10, all values are transformed into numbers between 0 and 10. By using the |