c++ - Why is my random generation of numbers input all zeros? -



c++ - Why is my random generation of numbers input all zeros? -

i have function template suppose take vector , produce random numbers within it. however, when print entire vector, zeros. method works arrays however.

code:

#include <vector> template<class t> class randomgenerator { public: // function template generating random numbers void genrand(t data[], int size) { (int = 0; < size; i++) { data[i] = (1 + rand() % size); } } void genrand(std::vector<t> data, int size) { genrand(&data[0], size); } };

you take vector value, argument won't changed. take reference:

void genrand(std::vector<t>& data, int size) // ^

c++ templates random vector

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -