Random numbers

i just created an object who store a vector of size 7 with
random numbers between 1 and 36. If i declare two objects i get
different vector, but running many times the program i always get the same vectors . For example, if i declare one object, even if i run any time the program, i always get the same numbers. I am using the function num= rand()%36+1,
wasn t it supposed to generate randoms numbers?
Thank you
Did you call srand() once at the start of your program?
rand() is in the constructor of my object, so everytime i declare the object should call the rand() function
There is a difference between "srand" and "rand" - it was not a typo.
oh ok,
so how could i create a different random value everytime i run the program?
you don't need nullptr you can just write srand(time(0));
Using 0 or NULL in place of nullptr is deprecated.
Last edited on
Topic archived. No new replies allowed.