C + + functions

Source: Internet
Author: User
Tags function prototype random seed
  1. RAND ()//66970397 54599083
    • Use the rand () function to produce a random integer within 1-100: int num = rand ()% 100 + 1;
    • General: Rand ()% (b-a+1) + A; Represents a random integer between the a~b.
    • RAND () function prototype: int rand (void);
    • The header file required by the rand () function is:<stdlib.h>/<cstdlib>
    • The random number produced by Rand () is the same as the last time it is run, and to produce a different random number each time, you can use the Srand (seed) function to produce a random seed, which can produce different random numbers as the seed is different. You can also include the time.h header file, and then use Srand (Time (0)) to randomize the random number generator using the current times, which guarantees that a different sequence of random numbers can be obtained every two times, and that it requires the program to run two times longer than 1 seconds.

C + + functions

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.