DA07A_Lecture

DA07A_Lecture - - Computer Programming Winter Quarter The...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
P. 1 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition Daily Assignment A07 A07 requires us to make up (generate) a random number between 0 and 10. Often, computer system have routines already available for generating a sequence of pseudo- random numbers. For today, we can use one such utility function: int answer ; answer = rand ( ) % 11 ;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P. 2 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition A Little Help for Assignment A07 But if we just use: answer = rand ( ) % 11 ; we'll get the same "random" value each time we run the program. So, how do we get something more "random"? We must first "seed" the random number generator: srand ( some_random_number ) ; So where do we get " some_random_number " ?
Background image of page 2
P. 3 Engineering H192
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition A Little Help for Assignment A07 On a UNIX system, the time of day (expressed in seconds) is "sort of" a random number: srand ( time (NULL) ) ; Where do these functions "live"? rand, srand functions are in <stdlib.h> time function is in <time.h> Check C Library resources P. 4 Engineering H192 - Computer Programming Winter Quarter The Ohio State University Gateway Engineering Education Coalition A Little Help for Assignment A07 How to control the game? (Use bottom test loop) int nguess, guess, answer ; /* seed random number generator here */ nguess = 0 ; answer = rand ( ) % 11 ; do { nguess++ ; /* game playing logic goes here */ } while ( guess != answer && nguess < 4 ) ;...
View Full Document

This note was uploaded on 08/05/2011 for the course H 192 taught by Professor Glimcher during the Winter '08 term at Ohio State.

Page1 / 4

DA07A_Lecture - - Computer Programming Winter Quarter The...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online