About random numbers C + +

Source: Internet
Author: User

1 voidTest ()2 {3Srand1);//The instructions here are set to start again from the beginning.4                     //if it is not set or based on the srand in the main function (1)5      for(intI=0;i<Ten; i++)6     {7cout << rand () <<Endl;8     }9 }Ten intMain () One { ASrand1); -      for(intI=0;i<Ten; i++) -     { thecout << rand () <<Endl; -     } -  - test (); + } -  + //therefore, Srand (time (nullptr)) is usually used in order to make different random numbers generated by each run of the program . A //A different sequence of random numbers will be generated as long as the time interval for each run of the program is greater than 1 seconds at //of course remember to set the Srand (time (0)) is enough, if a program is set multiple times within - //and the program runs out in a second, and then you're going to have a random number of loops.

About random numbers C + +

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.