Quick question
Anyone know of any functions that you can use to access the computer''s clock?? thatd be cool....and also....random number generators...but...id rather not download a library since thats someone else''s work...i was hopin there was a standard library that came with microsoft visual c++ that might have it...thanx
#include <mmsystem.h>
// seed the random number generator:
srand(timeGetTime());
// get a random number
int i = rand() % 10;
you have to link with winmm.lib
My Site
// seed the random number generator:
srand(timeGetTime());
// get a random number
int i = rand() % 10;
you have to link with winmm.lib
My Site
hey..cool....umm...u dont mind if i use that do u??? im not just gonna rip it off...but....could i include wut u did??
#include <mmsystem.h>
#include <iostream.h>
#include <winmm.lib>
int danrand(int smallest, int largest)
{
while (i>largest||i
{
// seed the random number generator:
srand(timeGetTime());
// get a random number
int i = rand() % 10;
}
return i;
}
and heres wut i got..figure i should give back right??? well...that is if it works anyways... thanx again
[edited by - Ademan on July 7, 2003 4:56:48 PM]
#include <iostream.h>
#include <winmm.lib>
int danrand(int smallest, int largest)
{
while (i>largest||i
{
// seed the random number generator:
srand(timeGetTime());
// get a random number
int i = rand() % 10;
}
return i;
}
and heres wut i got..figure i should give back right??? well...that is if it works anyways... thanx again
[edited by - Ademan on July 7, 2003 4:56:48 PM]
hmmm....it seems to not like it when i do i_<_smallest....wellyah...there is is (the missing block.....but then again...im in compsc 110..so its probably wrong anyways
int myRand(int min, int max)
{
return rand()%(max-min+1)+min
}
I think that is the function you''re looking for.
As far as I know, you only have to call srand() once (in your init). However, I have seen some weird behaviour from rand(), so I could be mistaken.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement