Why the rand ()% 100 function returns numbers greater than 100. I did not observe this before, at least in console versions. Here I tried to display a hidden number in the MessageBox.

srand(time(0)); int c_train=rand()%100; wchar_t buffer[30]; char buffer_c[20]; string value; string title="Значение: "; title=title+itoa(c_train,buffer_c,8); MultiByteToWideChar(CP_ACP,0,title.c_str(),-1,buffer,30); MessageBox(NULL, buffer, _T("Win32 Guided Tour"), NULL); 


    2 answers 2

    And everything correctly displays. Answer in line

     itoa(c_train,buffer_c,8); 

    namely, the number 8. You are asking to output in the number system on the base 8. Therefore, 64 will already look like 100.

    • 64 gives all kinds of letters and symbols - Dimka
    • 3
      if instead of 8 to write 64, yes ... it will give out :) 10 you need to write there. - KoVadim
    • Suspected. And you can find an explanation about this 3 parameters. What does it fix? And then in the aglitsky did not understand. - Dimka

    Because you print the number in octal numbering system (the third parameter in itoa).

    • I tried different but only 8 gave more or less adequate values. the rest and letters give out and tsiforki. - Dimka
    • four
      @ Dimka, you would not be engaged in programming, but in reverse engineering. - northerner
    • And what is it? :))) Or is it about how I convert values? :))) - Dimka
    • one
      @ Dimka "tried different" is five of course) That is, you do not know what the system of calculus? - rasmisha
    • Oddly enough, but in the know. :)))) Just "worn out." - Dimka