Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSIS 110 Lecture 22: Generating Random Numbers and DNA Sequences - Prof. Brian F. Hanks, Study notes of Javascript programming

The announcements, assignments, and exercises for csis 110 lecture 22, which covers generating random numbers and dna sequences using java's random class. Students are asked to read chapter 5, sections 5.1 to 5.4, complete a programming assignment, and take a quiz. The lecture also includes a lab exercise where students create a generate class to generate random dna sequences.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-8wy-1
koofers-user-8wy-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSIS 110 - Lecture 22
Announcements:
Quiz Wednesday.
Read Chapter 5, sections 5.1 to 5.4.
Programming Assignment on course web page
Midterm Grades: 25% Quizzes, 35% HW/Labs, 40% Programs
Random Numbers
In the real world, some things occur randomly, such as: flipping coins, rolling dice,
atomic decay. What are some other situations where randomness occurs or is useful?
- games
- simulations
- controlled experiments
- lottery
We'd like to be able to write programs that can do these sorts of things, but the programs
must have a source of random behavior. So far, every program we have seen does the
same thing every time it is run if it starts with the same data.
Java includes a class named Random. Let's go look it up.
Open BlueJ – go look it up in the Java documentation. (Help | Java Class Libraries ).
What package is it contained in? (That is, where do you need to tell Java to look for the
Random class in an import statement?)
How do you create an instance of a Random?
How do you generate a random number?
- create an instance of class Random
- call a method on that object to get a number
Open the random project (in chapter 5 directory). Go ahead and play around with it.
What do the methods do?
What is the difference between the two versions of printTenRandoms?
Let's look at the code in a little more detail…
Instance variable: a Random number generator
Constructor: Initialize the Random number generator
pf3

Partial preview of the text

Download CSIS 110 Lecture 22: Generating Random Numbers and DNA Sequences - Prof. Brian F. Hanks and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 - Lecture 22

Announcements: Quiz Wednesday. Read Chapter 5, sections 5.1 to 5.4. Programming Assignment on course web page Midterm Grades: 25% Quizzes, 35% HW/Labs, 40% Programs Random Numbers In the real world, some things occur randomly, such as: flipping coins, rolling dice, atomic decay. What are some other situations where randomness occurs or is useful?

  • games
  • simulations
  • controlled experiments
  • lottery We'd like to be able to write programs that can do these sorts of things, but the programs must have a source of random behavior. So far, every program we have seen does the same thing every time it is run if it starts with the same data. Java includes a class named Random. Let's go look it up. Open BlueJ – go look it up in the Java documentation. (Help | Java Class Libraries ). What package is it contained in? (That is, where do you need to tell Java to look for the Random class in an import statement?) How do you create an instance of a Random? How do you generate a random number?
  • create an instance of class Random
  • call a method on that object to get a number Open the random project (in chapter 5 directory). Go ahead and play around with it. What do the methods do? What is the difference between the two versions of printTenRandoms? Let's look at the code in a little more detail… Instance variable: a Random number generator Constructor: Initialize the Random number generator

Methods: use the random number generator to create random numbers. randomGenerator.nextInt() randomGenerator.nextInt( max ) Let's say that we wanted to use a random number generator to simulate rolling a single die. What values do we need to generate? How would we do this?