C language random number function example _c language

Source: Internet
Author: User
Tags generator rand

void Srand (unsigned int seed);
Head file is <stdlib.h>
Remarks
The Srand function sets the starting point for generating a series of pseudorandom
Integers. To reinitialize the generator, use 1 as the seed argument. Any other value for
The seed sets the generator to a random starting point. Rand retrieves the pseudorandom
Numbers that are generated. Calling Rand before any call to Srand generates the same
Sequence as calling Srand with seed passed as 1.

Copy Code code as follows:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
void Main (void)
{
int i;
/* Seed the Random-number generator with
* The numbers is different every time we run.
*/
Srand ((unsigned) time (NULL));
/* Display ten numbers. */
for (i = 0; I < 10;i++)
printf ("%6d\n", Rand ());
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.