This exercise will show you how to generate and display random numbers containing decimal places. Open the

Question:

This exercise will show you how to generate and display random numbers containing decimal places. Open the Random Double Solution (Random Double Solution.sln) file contained in the VB2015\Chap05\Random Double Solution folder.

a. Open the Code Editor window. You can use the Random.NextDouble method to return a random number that is greater than or equal to 0.0 but less than 1.0. The syntax of the Random.NextDouble method is randomObjectName.NextDouble. Code the btnDisplay_Click procedure so that it displays a random number in the lblNumber control. Save the solution and then start the application. Click the Display Random Number button several times. Each time you click the button, a random number that is greater than or equal to 0.0 but less than 1.0 appears in the lblNumber control.

b. You can use the following formula to generate random numbers within a specified range: (maxValue – minValue + 1) * randomObjectName.NextDouble + minValue. For example, if the Random object’s name is randGen, the formula (10 – 1 + 1) * randGen.NextDouble + 1 generates random numbers that are greater than or equal to 1.0 but less than 11.0. Modify the btnDisplay_Click procedure to display a random number that is greater than or equal to 25.0 but less than 51.0. Display two decimal places in the number. Test the application several times.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: