An example:
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int getRandom(){ return rand() % 500; }
int main(){
srand(time(0)); //seed random number function
int size = 0;
cout << "Enter size: ";
cin >> size;
std::vector<int> data(size,0); // contains size number of 0's
std::generate(data.begin(), data.end(), getRandom ); //fill vector with random numbers from [0,500)
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608