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

后端 未结 5 1145
生来不讨喜
生来不讨喜 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 13:11

    Option 2 isn't difficult, here you go:

    srand(time(NULL));
    

    you'll need to include stdlib.h for srand() and time.h for time().

提交回复
热议问题