{small lecturenumber - heblocknumber :} Announcementsaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Academic Honestyaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Academic Honestyaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Random Numbersaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Random Numbersaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Pseudo-Random Numbersaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Pseudo-Random Numbersaddtocounter {blocknumber}{1}{small lecturenumber - heblocknumber :} Example!addtocounter {blocknumber}{1}Intro to Computer Science IICS112-2012S-07Building Larger ProgramsDavid GallesDepartment of Computer ScienceUniversity of San Francisco07-0: AnnouncementsLabs 1 and 2 to be returned today, see me if youhave any questionsLate policy shift, starting with Project 1: 50%reduction until 24 hours after due dateStyle requirementAcademic HonestyWhat is allowed?What is not allowed?07-1: Academic HonestyWhat is allowed: You may talk with other studentsabout:Generic Java: how classes work, how controlstructures (while/for/if/etc) work, etcAnything covered in class, in the textbook, etc.Assignment requirements: What your codeshould do, what input/output should be, etc.High Level algorithms (Example: inserting intosorted array)07-2: Academic HonestyWhat not allowed:You may not look an another student’s codeYou may not copy another student’s codeYou may not copy code from the web / anyother source and submit it as your own work07-3: Random NumbersWhat if we wanted random numbers (for a dicegame, for example)import java.util.Random;class Test{public static void main(String[] args){Random r = new Random();int randnum = r.nextInt(25);}}r.nextInt(25) returns a value between 0 and 2407-4: Random NumbersThere are no “real” random numbers in JavaComputers are deterministic!That is, they work the same way on the samedata, every time – the output is determined bythe input.Java uses Pseudo-Random numbers insteadNot “really” random, but “look” random07-5: Pseudo-Random NumbersCreate a sequence of numbers that “look random”Bounce all over the number lineStart with a “seed”, initial numberFunction that takes previous number, return thenext one in the sequenceXi= (aXn+ c) mod m07-6: Pseudo-Random NumbersWe can “seed” the Random constructor, by givingthe first element in the sequenceRun the program twice, the same exact seqence ofrandom numbers will occur, great for debuggingIf we don’t give the Random constructor a seed,picks number of miliseconds that have elapsedsince Jan 1, 197007-7: Example!User rolls two dice up to three times to try to beat arandomly generated targetAfter each roll, user decides to roll again or stickwith current rollDriver - mainGame - play //main logicPlayer - all input/outputDie - 6 sided
View Full Document