What difference between rand() and random() functions?

后端 未结 7 1315
抹茶落季
抹茶落季 2020-12-05 07:58

Once, my teacher taught me to use randomize() and random() function for generating pseudorandom numbers in C++ Builder. Now I prefer working in VS

7条回答
  •  庸人自扰
    2020-12-05 08:29

    It looks like you were using C-style functions, even though your question is labeled C++. Also, stdlib.h is a header file from C standard library. There's no such functions are random() and randomize() in C standard library. The C standard library has rand() and srand().

    If you were using random() or something like that through stdlib.h, it must have been some non-standard library extension in Borland compiler package.

    So, if you want to stick to C-style standard functions, that would be, again, rand() and srand(). But if you are writing in C++, you might have better (and more appropriate) options in C++ standard library.

提交回复
热议问题