From the course: C Standard Library
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Challenge: Let's get random - C Tutorial
From the course: C Standard Library
Challenge: Let's get random
(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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Memory allocation1m 32s
-
Memory allocation example2m 29s
-
Random number generation1m 48s
-
Random number generation example2m 40s
-
String conversion2m 11s
-
String conversion example6m 29s
-
Sort and search1m 52s
-
Sort and search main4m 50s
-
Sort and search functions5m 6s
-
Challenge: Let's get random1m 38s
-
Solution: Let's get random5m 40s
-
-
-
-