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
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.
Step by Step Solution
3.27 Rating (162 Votes )
There are 3 Steps involved in it
Microsoft Visual Studio Solution File Format Version 1200 Visual Studio 14 VisualStudioVersion 140225120 MinimumVisualStudioVersion 100402191 ProjectF184B08FC81C45F6A57F5ABD9991F28F Random Double Proj... View full answer
Get step-by-step solutions from verified subject matter experts
