What does this code do?


void PickRandomNumbers()
{
int intNumber1;
double dblNumber;
int intNumber2;
Random objRandom = new Random();

intNumber1 = objRandom.Next();
dblNumber = 5 * objRandom.NextDouble();
intNumber2 = objRandom.Next( 1, 10 );

lblInteger1.Text = Convert.ToString( intNumber1 );
lblDouble1.Text = Convert.ToString( dblNumber );
lblInteger2.Text = Convert.ToString( intNumber2 );

} // end method PickRandomNumbers

intNumber1 gets a positive integer (between 0 and Int32.MaxValue), dblNumber

gets a floating-point number between 0 and 5 (not including 5) and intNumber2 gets an integer between 1 and 10 (not including 10). The complete code reads:





// RandomNumber.cs



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace RandomNumber

{

///

/// Summary description for FrmRandomNumber.

///


public class FrmRandomNumber : System.Windows.Forms.Form

{

private System.Windows.Forms.Label lblInteger2;

private System.Windows.Forms.Label lblDouble1;

private System.Windows.Forms.Label lblInteger1;

private System.Windows.Forms.Label lblRandomInt2;

private System.Windows.Forms.Label lblRandomDouble;

private System.Windows.Forms.Label lblRandomInt;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



public FrmRandomNumber()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



//

// TODO: Add any constructor code after InitializeComponent

// call

//

}



///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



// Windows Form Designer generated code



///

/// The main entry point for the application.

///


[STAThread]

static void Main()

{

Application.Run( new FrmRandomNumber() );

}



// calls the PickRandomNumbers helper method

private void FrmRandomNumber_Load(

object sender, System.EventArgs e )

{

PickRandomNumbers();



} // end method FrmRandomNumber_Load



// chooses and displays several random numbers of various types

void PickRandomNumbers()

{

int intNumber1;

double dblNumber;

int intNumber2;

Random objRandom = new Random();

intNumber1 = objRandom.Next();

dblNumber = 5 * objRandom.NextDouble();

intNumber2 = objRandom.Next( 1, 10 );

lblInteger1.Text = Convert.ToString( intNumber1 );

lblDouble1.Text = Convert.ToString( dblNumber );

lblInteger2.Text = Convert.ToString( intNumber2 );

} // end method PickRandomNumbers

} // end class FrmRandomNumber

}



Computer Science & Information Technology

You might also like to view...

Match the following terms to their meanings:

I. RunMacro II. Trusted Location III. Action Catalog Pane IV. MessageBox V. Status Bar text A. Action used to run a macro from within another macro B. This text argument displays text on the status bar while macro is running if Echo On set to "No" C. Can search for an action using this D. The warning or information can contain up to four arguments E. If a macro action is not trusted, you must add the location of the database here for the macro to execute properly

Computer Science & Information Technology

When a loan is repaid, the total principal matches the ________ for the final payment

A) total interest B) cumulative principal C) present value D) future value

Computer Science & Information Technology