When writing a program, you will often encounter a place with a random function. Here I give a simple way, similar things in MSDN. To create a true random number, it is more complicated, but it is not necessary for most applications.
Sample code:
// name: rand_example.cpp // compile: CL / EHSC RAND_EXAMPLE.CPP / / OS: Window 2000 or Later
#include
Template
Inline int random (int min) {return ((rand ()% (MAX 1-min)) min);
Int main () {typedef st :: vector
SRAND (NULL);
For (int i = 0; i <10; i) MyArray.push_back (Random (10, 60));
FOR_EACH (MyArray.begin (), MyArray.end (), Display
Return 0;}
In the above program, the number of random numbers can be obtained, and if the precision is high, consider using Win32 API QueryPerFormanceCounter to obtain higher precision time values as a seed value.