"C + +" generates random numbers

Source: Internet
Author: User

1#include <iostream>2#include <Ctime>3#include <Cstdlib>4 using namespacestd;5 #defineMIN 16 #defineMAX 1007 intMain ()8 {9     DoubleRandomDouble,Double);TenSrand ((unsigned) time (NULL));//set Random seed One      for(intcn=0;cn<Ten; cn++) Acout<<int(Random (Min,max)) <<" "; -cout<<Endl; -     return 0; the } - DoubleRandomDoubleStartDoubleend) - { -     returnMin+rand ()% (max+1);////rand () returns an integer from 0 to Rand_max.  +}

"NOTE"

Because it takes a long time to set a random seed statement, it is best to place it outside the loop structure if multiple random numbers need to be taken.

The Rand_max,<stdlib.h> header file has the following predefined:

——————————————————————————————————

#define RAND_MAX 0X7FFF

——————————————————————————————————

0X7FFF is the decimal 32767

"C + +" generates random numbers

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.