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

Challenge: Let's get random - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

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…

Contents