/
Lecture Set 9 Arrays, Collections and Repetition Lecture Set 9 Arrays, Collections and Repetition

Lecture Set 9 Arrays, Collections and Repetition - PowerPoint Presentation

alexa-scheidler
alexa-scheidler . @alexa-scheidler
Follow
342 views
Uploaded On 2019-12-12

Lecture Set 9 Arrays, Collections and Repetition - PPT Presentation

Lecture Set 9 Arrays Collections and Repetition Part C Random Numbers Rectangular and Jagged arrays 142016 1004 PM Objectives Understand the concept of random numbers and how to generate random numbers ID: 770094

arrays random array 2013 random arrays 2013 array dimensional seed generate number declare int rndvalr jagged class optional textboxlist

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Lecture Set 9 Arrays, Collections and Re..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Lecture Set 9 Arrays, Collections and RepetitionPart C - Random NumbersRectangular and Jagged arrays 1/4/2016 10:04 PM

Objectives Understand the concept of random numbers and how to generate random numbersUnderstand how to declare and manipulate rectangular and higher dimension arrays Understand how to declare and manipulate jagged arrays Working with arrays of objects 1/4/2016 10:02 PM

Introduction to Random Numbers Applications that require random numbersGaming and casino applicationsComputer simulations Test data generation The process of creating a sequence of random numbers is called random number generation 8/18/2013 1:06 PM

Operation of a Random Number Generator A random number generator is initialized based on a seed value Given the same seed value, the same random number sequence will be generated Seed = r0, r 1 , r 2 , … where usually r i = f(ri-1)Different seed values will generate different random sequencesThe time of day (often expressed in milliseconds) is often used to create random seed valuesIf you do not use a different seed every time you execute your program, the random number gene-rator will generate the same sequence of numbers 8/18/2013 1:06 PM

The System.Random Class The System.Random class of the FCL is used to create a random number generator and generate and get random values We can generate integer and double random values The constructor of the System.Random class creates the random number generator (an instance of the random class) Using no constructor arguments, a random seed value is used The seed value is based on the time of day Random rndVal = new Random();This is the same as Random rndVal = new Random(DateTime.Now.Millisecond); 1/4/2016 10:05 PM

The Next MethodWithout arguments, the Next method gets a positive random Integer value Random rndValR = new Random;;int rndValI = rndValR.Next ();With two arguments, a value within a range is returnedThe first argument contains the lower bound and the second argument contains the upper boundrndValI = rndValR.Next(1, 10);rndValI = rndValR.Next(1, 6);// Let index be an integerindex = rndValR.Next (0, myDictionaryWords.Length - 1);The second line could be used to generate the value of the roll of a single die. How would you generate a random value representing the roll of two dice? 1/4/2016 10:06 PM

The NextDouble MethodThe NextDouble method returns a random value between 0.0 and 1.0 The value is in the interval [0.0<=value<1.0) Closed on the left and open on the right Example: double randomDouble;randomDouble = _ rndValR.NextDouble ()‘A value such a .4599695143908786 is generated8/18/2013 1:06 PM

Introduction to Two-dimensional Arrays A two-dimensional array has rows and columnsConceptually, it's similar to a grid or table Two-dimensional arrays have two subscripts instead of one Declare a two-dimensional array with unspecified dimensions int [,] Table; Declare a two-dimensional array with 10 rows and 10 columns int [9, 9] Table; 8/18/2013 1:06 PM

Initializing Two-dimensional Arrays Two-dimensional arrays can be initialized just as one-dimensional arrays can be initializedThe array must not be given an initial sizeThe initialization list is nested as follows: int SalesArray [,] = { {150, 140, 170, 178}, {155, 148, 182, 190}, {162, 153, 191, 184}, {181, 176, 201, 203} }; 8/18/2013 1:06 PM

Referencing Elements in a Two-dimensional ArrayTwo-dimensional arrays require two subscripts instead of one A comma separates the two subscripts Reference the first row and column in the array named SalesArray int cell; cell = SalesArray [0, 0]; 8/18/2013 1:06 PM

Introduction to Three-dimensional Arrays (optional)It's possible to create arrays with three dimensionsA three-dimensional array has three subscripts instead of two Declare a dynamic three-dimensional array int cube[,,]; Declare a 10 by 10 by 10 array (1000 elements) double cube[10, 10, 10]; 8/18/2013 1:06 PM

Working with Arrays of Objects Arrays can store object references in addition to storing primary data typesExample to store text box references: textbox [3] textBoxList ; textBoxList [0] = txtFirstName ; textBoxList[1] = txtLastName;textBoxList [2] = txtAddress ;What does this array look like?8/18/2013 1:06 PM

Memory Allocation to Store an Array of Text Boxes (VB) 8/18/2013 1:06 PM

Another View of 2D (Rectangular) Arrays 8/18/2013 1:06 PM

Operations on a 2-Dimension Array 8/18/2013 1:06 PM

More Operations on a 2-Dimension Array 8/18/2013 1:06 PM

Jagged Arrays (by Example) 8/18/2013 1:06 PM

Jagged Array References (optional)I am not sure you will have occasion to do this – but maybeThe example is interesting from a pedagogic view It illustrates memory allocation issues discussed already 8/18/2013 1:06 PM

More Jagged Array (examples – optional) 8/18/2013 1:06 PM

Yet ANOTHER Example (optional) 8/18/2013 1:06 PM