rand() gives only one number...

This is a discussion on rand() gives only one number... within the C++ Programming forums, part of the General Programming Boards category; Hey.
Im a new C++ programmer and having trouble using rand() in programs.
the only number rand returns is 41.
...

rand() gives only one number...

Hey.
Im a new C++ programmer and having trouble using rand() in programs.
the only number rand returns is 41.
Is there anything I can do to make it generate other numbers?
Or is there any better generators?
Thank you for reading this thread and have a good day =).

Remember that the seed must be initialized with a unique number, because a randomizer is basically just an algorithm applied to a unique number.
This is why we see this particular line of code very often.
Once you read the documentation on time, it should be clear.

Random number generators are generally not really random, but fully deterministic and thus "psuedo-random". That simply means that if you give a particular implementation the value 3114 it will generate the same sequence of numbers everytime. Naturally, you'll probably want to get different values in most cases, so you need a function that can produce an ever-changing flow of numbers, and the 'time' function is one such source. But there are other possibilities, of course. You could access the CPU temperature, for instance, and produce a seed from that.