samedi 19 décembre 2020

problem generating a random sequence of binary numbers (c++)

#include <iostream>
#include <random>
#include <string>
#include <chrono>

using namespace std;

string string_maker5000(int length)
{
    unsigned seed = std::chrono::steady_clock::now().time_since_epoch().count();
    default_random_engine e(seed);
    string stringcheese;
    for (int i = 1; i <= length; i++)
    {
        uniform_int_distribution<int> distr(0, 1);
        int n = distr(e);
        stringcheese = ": ";
        stringcheese += n;
    }
    return stringcheese;
}
int main()
{
    string yee = string_maker5000(5);
    cout << yee << endl;
}

I'm pretty new to programming as a whole and have been trying to learn some C++. Anyways, when ever I run the program instead of it outputting 1s and 0s it outputs question mark boxs for the ones I think, and it appears to output 0 as blanks... not really sure. Makes me think its some type of problem with utf or something. here is a screen shot of what happens. Also anyone know a way to make it more random? it appears too (if my hypothesis is correct) lean heavily in favor of 0s.




Aucun commentaire:

Enregistrer un commentaire