random binary number generator

Hello
I wrote this piece of code for generating a random binary number with two for loop like the following:

there are 2 problems :
1) when I replace it in the proper place in my whole code, the compiler(in visual studio 2017) give me a warning about this line: srand(time(0)); that (Warning C4244 'argument': conversion from 'time_t' to 'unsigned int', possible loss of data)

2)how I can decrease the number of for loop to have just one for loop?
Last edited on
1
2
3
4
5
6
    srand(static_cast<unsigned int>(time(0)));
    for (i = 0; i < 10; i++) {
        buffer.push_back(rand() % 2);
        cout << buffer[i] << ' ';
    }
    cout << '\n';

Last edited on
@tpb

when I want to replace this piece of code to my whole code, I must put the value of i in the for loop like this: for (i = 1; i < =4; i++)
when I change it the output is not the desired output
if I put for loop with the same range that you used for (i = 0; i < 10; i++)

why it occurs?
I don't know. You would have to post your whole code.
could you please also solve an error that exists in my written code which I mentioned in my first post above?
The error is fixed with this
std::srand(unsigned(std::time(0)));

Topic archived. No new replies allowed.