Search code examples
c++randomunsigned-char

Random numbers on unsigned chars keeps being '?'


I've previously asked a question related to generating a random unsigned char and pretty good suggestions came along the way however due to simplicity I've applied ; srand((unsigned)time(NULL)); rand()%256;

I call the srand one time at the beginning of the program, however I keep getting '?' for a random char. Not all the time but most of the time and that causes me to lose my focus.


Solution

  • Most probably you keep getting random chars that your terminal does not need how to print and outputs ?. Try converting them to int before printing:

    std::cout << (int)my_random_char;