Recommended way to initialize srand?

前端 未结 15 1844
夕颜
夕颜 2020-11-22 08:07

I need a \'good\' way to initialize the pseudo-random number generator in C++. I\'ve found an article that states:

In order to generate random-like

15条回答
  •  无人共我
    2020-11-22 08:44

    #include 
    #include 
    main()
    {
         struct timeval tv;
         gettimeofday(&tv,NULL);
         printf("%d\n",  tv.tv_usec);
         return 0;
    }
    

    tv.tv_usec is in microseconds. This should be acceptable seed.

提交回复
热议问题