Compatibility In C, the generation algorithm used by rand is guaranteed to only be advanced by calls to this function. In C, this constraint is relaxed, and a library implementation is allowed to advance the generator on other circumstances (such as calls to elements of ). In comparison, Microsoft Visual C implementation always returns 32, and boost.random returns 10. The entropy of the Linux kernel device /dev/urandom may be obtained using ioctl RNDGETENTCNT - that's what std::randomdevice::entropy in GNU libstdc uses as of version 8.1 Example.
- The C Standard Library
- C Standard Library Resources
- C Programming Resources
- Selected Reading
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.
C++ Random Float
Example
The following example shows the usage of rand() function.
Let us compile and run the above program that will produce the following result −
Dev Random Dev Urandom
- The C Standard Library
- C Standard Library Resources
- C Programming Resources
Dev C Random Library Function
- Selected Reading
Description
The C library function void srand(unsigned int seed) seeds the random number generator used by the function rand.
Declaration
Following is the declaration for srand() function.
Parameters
seed − This is an integer value to be used as seed by the pseudo-random number generator algorithm.
Return Value
This function does not return any value.
Example
Dev C Random Library In Windows 10
The following example shows the usage of srand() function.
C++ Rand
Let us compile and run the above program that will produce the following result −