Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 04-30-2009, 07:56 PM   #1
In Runtime
 
Join Date: Dec 2001
Posts: 154
Default c++ random number generator

When i try using the random number generator I receive two errors
the first one:missing type specifier - int assumed. Note: C++ does not support default-int
the second : 'srand' : redefinition; previous definition was 'function'

i have the ctime lib being called

to declare the generator I have: This line i copied from another program that works fine.
srand (time(0));

the program then goes to a function called GetTheNumber()
in main I have it coded as generated = GetTheNumber();

in the GetTheNumber function
int GetTheNumber ()
{
int generated;
generated = 1 + rand() % 1000;
return generated;
}

I want the numbers betweet 1 and 1000 randomly generated.

When I look at the other program everything looks the same. Any help would be appreciated

Thanks in advance
__________________

Hid_Enigma is offline   Reply With Quote
Old 05-08-2009, 07:28 PM   #2
Solid State Member
 
Join Date: May 2009
Posts: 7
Default Re: c++ random number generator

generated = 1 + rand(THERE IS NO ARGUMENTS HERE) % 1000;
__________________

disassociation is offline   Reply With Quote
Old 05-09-2009, 11:12 AM   #3
In Runtime
 
Join Date: Dec 2001
Posts: 154
Default Re: c++ random number generator

Thanks for responding I had srand(time(0)) outside of main instead of putting it inside. Once I moved the code it worked;.
Hid_Enigma is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 07:07 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0