C program to generate pseudo-random numbers using rand and random function (Turbo C compiler only). As the random numbers are generated by an algorithm used in a function they are pseudo-random, this is the reason that word pseudo is used. Function rand returns a pseudo-random number between 0 and RANDMAX.
-->The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at rand.
Generates a pseudorandom number. A more secure version of this function is available, see rand_s.
Syntax
Return Value
rand
returns a pseudorandom number, as described above. There is no error return.
Remarks
The rand
function returns a pseudorandom integer in the range 0 to RAND_MAX
(32767). Use the srand function to seed the pseudorandom-number generator before calling rand
.
Requirements
Routine | Required header |
---|---|
rand | <stdlib.h> |
For additional compatibility information, see Compatibility in the Introduction.
Example
.NET Framework Equivalent
See Also
Floating-Point Support
srand
rand_s