Let's put the random number generator to the test. Write an application that generates a very large number of random values from 1 to 1000, and then report what percentage of those numbers were less or equal than 500. This result should approach 50% when
(upbeat music)…- [Instructor] Here's another challenge to test what…you've learned about random number generation…in the stdlib.h header file.…Let's put the random number generator to the test.…We want random number generators to behave as close…as possible to truly random.…That is, we want every possible number to be equally…likely to come up as any other number.…This is known as a uniform probability distribution.…
An easy way to detect a non-uniform distribution…for the rand function, is to calculate the probability…of a random number to fall within the lower half…of the random number range.…This probability should be 0.5 or 50 percent.…For this challenge, you should use the functions in stdlib.h…so again don't worry about validating special cases.…Now let me give you a little push by showing you a simple…approach to calculate this probability.…
You may write a loop that iterates a lot of times,…I mean hundreds of thousands or even millions of iterations.…This loop should generate values from say one to 1000…
- 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.