Srandom () and random () are used in the VC ++ program. The header file is stdlib. h, but the compilation Error error c3861: "srandom": the identifier cannot be found.
The reason is that the library functions of the VC ++ compiler do not include randomize () and random (), which are replaced by srand () and rand () respectively.
# Include <time. h> // defines the time function.
This header file is usually required when the time (null) (current time) function is used.
# Include <stdlib. h> // defines miscellaneous functions and memory allocation functions.
This header file is usually required when you use the rand () and srand () functions.
Function Name: Random Function: random number generator, that is, a random number is generated.
Usage: int random (INT num );
The random number range is 0 ~ Num-1.
Function Name: randomize
Function: Initialize the random number generator, which is equivalent to allocating random seeds.
Usage: void randomize (void );
#include <iostream>#include <stdlib.h> // Need random(), srandom()#include <time.h> // Need time()#include <algorithm> // Need sort(), copy()#include <vector> // Need vectorusing namespace std;void Display(vector<int>& v, const char* s);int main(){// Seed the random number generatorsrand(time(NULL));// Construct vector and fill with random integer valuesvector<int> collection(10);for (int i = 0; i < 10; i++) collection[i] = rand() % 10000;// Display, sort, and redisplayDisplay(collection, "Before sorting");sort(collection.begin(), collection.end());Display(collection, "After sorting");return 0;}// Display label s and contents of integer vector vvoid Display(vector<int>& v, const char* s){cout << endl << s << endl;copy(v.begin(), v.end(),ostream_iterator<int>(cout, "\t"));cout << endl;}