What's the Right Way to use the rand() Function in C++?

后端 未结 5 1141
生来不讨喜
生来不讨喜 2020-11-29 12:16

I\'m doing a book exercise that says to write a program that generates psuedorandom numbers. I started off simple with.

#include \"std_lib_facilities.h\"

in         


        
5条回答
  •  一向
    一向 (楼主)
    2020-11-29 12:50

    It is common to seed the random number generator with the current time. Try:

    srand(time(NULL));

提交回复
热议问题