Join Eduardo Corpeño for an in-depth discussion in this video Random number generation example, part of C Standard Library.
- [Instructor] So to illustrate these random,…number-generation functions, let's…write an application that will help us…in raffle, where the numbers are from one to 10 thousand.…So, we want to draw a number,…a random number, and report it.…So, let me start by using a variable in line eight that…is an unsigned integer of 32 bits called winner.…
So, that's where we'll store the winner,…and let's initialize the random number generator.…That's srand for the random seed,…and I will use the system time.…This time function takes in an argument which can be zero…for us to just take the current time.…And now, let's write this program,…so that we can draw several numbers.…Maybe the raffle is for several prizes.…
So, let's write this in a while loop,…and I will use a terminal for this.…So, and we'll use get char, and as long as I don't…receive the character x, I will keep on drawing numbers.…And now we need to call the rand function.…So, my winner variable will equal rand.…Now, remember, rand is a number…between zero and a very large number.…
- Working with header files
- C constants and types
- Unformatted and formatted input/output
- Accessing files with C functions
- Generating random numbers
- Converting strings
- Sorting and searching for data
- Manipulating strings
- Using mathematical functions
Skill Level Intermediate
C++ Standard Template Librarywith Eduardo Corpeño2h 23m Advanced
1. The C Standard Library
2. Input and Output Library: stdio.h
3. General Purpose: stdlib.h
4. String Functions: string.h
5. Mathematical Functions: math.h
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.