Nov 20, 2016 Using a modulus operator with the rand method gives a range to the random integer generation. Num = rand% 10 indicates the compiler than the random integer should be within 0 and 10, where 10 acts as the RANDMAX value. This is how you can generate a random number in C programming. The rand function returns a pseudorandom integer in the range 0 to RANDMAX (32767). Use the srand function to seed the pseudorandom-number generator before calling rand. Oct 01, 2012 This is me making a Random Number Generator in Dev C, I hope you like it, please give it a thumbs up & subscribe:) Click here to see my other cool program.
- The C Standard Library
- C Standard Library Resources
- C Programming Resources
- Selected Reading
Random Function Dev C++
Description
The C library function int rand(void) returns a pseudo-random number in the range of 0 to RAND_MAX.
RAND_MAX is a constant whose default value may vary between implementations but it is granted to be at least 32767.
Declaration
Following is the declaration for rand() function.
Parameters
- NA
Return Value
This function returns an integer value between 0 and RAND_MAX.
Example
The following example shows the usage of rand() function.
Download cooking mama for nintendo dsi. Let us compile and run the above program that will produce the following result −
stdlib_h.htm