{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

DA07A_Lecture

# DA07A_Lecture - Computer Programming Winter Quarter The...

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

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 ;

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

View Full Document
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 " ?
P. 3 Engineering H192

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

View Full Document
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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online