# Rand function not random



## aliasnikhil (May 13, 2009)

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


----------



## jamiemac2005 (Jul 5, 2007)

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


----------

