Fill a vector with random numbers c++

后端 未结 8 1271
难免孤独
难免孤独 2020-12-14 17:55

I\'ve got a vector that I\'m trying to fill up with random numbers. I keep running into an issue however that the vector mostly outputs 0 each time that I\'m running it (it

8条回答
  •  执笔经年
    2020-12-14 18:18

    What about simply:

    #include 
    #include 
    #include 
    
    std::srand(unsigned(std::time(nullptr)));
    std::vector v(1000);
    std::generate(v.begin(), v.end(), std::rand);
    

提交回复
热议问题