Tech Support Forum banner

Rand function not random

2145 Views 1 Reply 2 Participants Last post by  jamiemac2005
Hey guys,
i was tying some simple programs in c++ when i came across rand function in two programs.it should generate a totally new number every time.but my complier,which is ,DEV C++,generates the number 41 everytime.i tried restarting the complier but it did the same.
also my complier highlights all known functions but this time it did not highlight rand().I had included the <cstdlib> header.also when the output is to be generated i have to ALWAYS include the command cin.get() to keep the command prompt window open
PLEASE suggest solutions
THANKS IN ADVANCE
Status
Not open for further replies.
1 - 1 of 2 Posts
Hey, the tutorial here will help you: http://www.cprogramming.com/tutorial/random.html

Basically, rand needs a seed from somewhere(usually the time, converted to seconds) in order to generate a random number, and if you don't set that seed then you'll always get the same output.

So read the tutorial, if it still does it(which it shouldn't) post back and include your code =]

Cheers,
Jamey
1 - 1 of 2 Posts
Status
Not open for further replies.
Top