1 / 6

ECE 103 Engineering Programming Chapter 51 Random Numbers

ECE 103 Engineering Programming Chapter 51 Random Numbers. Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE. Syllabus. srand() sand(). Random Number Generator

denim
Download Presentation

ECE 103 Engineering Programming Chapter 51 Random Numbers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECE 103 Engineering ProgrammingChapter 51Random Numbers Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE

  2. Syllabus • srand() • sand()

  3. Random Number Generator C has library functions to input and output strings. Use #include <stdio.h> In the following table, char * is a pointer to a character array that contains a string. RNG Functions 2

  4. String I/O Functions C has library functions to input and output strings. Use #include <stdio.h> In the following table, char * is a pointer to a character array that contains a string. String I/O Functions 3

  5. srand intprintf (const char * format, …) Writes formatted output to the console. Use the %s format specifier for strings. %s expects the address of a char array which contains a string. Example: char name[] = "Jane Doe"; printf("[%s]\n", name); →[Jane Doe] printf("[%s]\n", &name[0]); →[Jane Doe] printf("[%s]\n", &name[5]); →[Doe] 4

  6. rand intsprintf (char * s, constchar * format, …) Performs a formatted print and saves it to a string. Works like printf except the output is stored in string s. Nothing is printed to the console. Example: char str[50]; intx = 4; sprintf(str,"x=%d y=%f", x, 1.5f); printf("title = %s\n", str); 5

More Related