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-23-2008, 05:18 PM   #1
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default random(), randomize()

Hi.

Are these functions just dead? They work in Visual C++ 6.0 but not in Visual Studio 2008. If so what header works properly so I can program at home using Visual Studio 2008 and bring it into school where we use C++ 6.0

Please, please DONT MENTION I HAVE TO USE CSTDLBIEWFWO AND RAND() ETC... THAT WON'T HELP. JUST PLEASE ANSWER MY QUESTION.
__________________

shoover is offline   Reply With Quote
Old 04-23-2008, 05:49 PM   #2
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: random(), randomize()

Wait, did you use time.h? You need that and use rand(). I know you said not to say that, but that's how it is. If you want another way, google it.
__________________

JogaBonito1502 is offline   Reply With Quote
Old 04-23-2008, 09:56 PM   #3
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: random(), randomize()

the command srand(Time.NULL) takes place of randomize.

oh, and joga, I've always seen it used as time.h not ctime.h maybe changing time.h (if that's what he's using) to ctime will fix it.
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 04-23-2008, 10:04 PM   #4
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: random(), randomize()

Oh yes Celegorm you are correct. It's been a while since I have last used random numbers.
JogaBonito1502 is offline   Reply With Quote
Old 04-23-2008, 10:13 PM   #5
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default Re: random(), randomize()

Okay thanks guys for your help. Can you tell me the parameters for rand(), such as declaring minimum and maximum integers randomly being picked?
shoover is offline   Reply With Quote
Old 04-23-2008, 10:22 PM   #6
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: random(), randomize()

Code:
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
  int iSecret, iGuess;

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate secret number: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;
}
Credit to: CPlusPlus.com (Click on link for more information)
JogaBonito1502 is offline   Reply With Quote
Old 04-23-2008, 10:34 PM   #7
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default Re: random(), randomize()

warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

on the srand ( time(NULL) ); statement
shoover is offline   Reply With Quote
Old 04-23-2008, 10:37 PM   #8
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: random(), randomize()

Oh dude, just ignore that. It's just a warning. It happened to me too, but I ignored it and it was fine.
JogaBonito1502 is offline   Reply With Quote
Old 04-23-2008, 10:38 PM   #9
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default Re: random(), randomize()

Well I got like 8 other random conversions in my program so ill get back to you on the results. Thanks for your help!
shoover is offline   Reply With Quote
Old 04-23-2008, 10:41 PM   #10
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: random(), randomize()

No problem man. I never use random conversions. I had to for my semester final. So I just made a number guessing game which was really boring. If you want to see the code for that I can send you the file.
__________________

JogaBonito1502 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 02:37 AM.


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