Zero if successful, otherwise, an error code. If the input pointer randomValue is a null pointer, the function invokes an invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, the function returns EINVAL and sets errno to EINVAL. If the function fails for any other reason, *randomValue is set to 0.

The rand_s function writes a pseudorandom integer in the range 0 to UINT_MAX to the input pointer. The rand_s function uses the operating system to generate cryptographically secure random numbers. It does not use the seed generated by the srand function, nor does it affect the random number sequence used by rand.

The rand_s function requires that constant _CRT_RAND_S be defined prior to the inclusion statement for the function to be declared, as in the following example: