void main()
{
int rand;
rand=random(10);
cout<<rand;<br>
}
but DJGPP gives me an error in stdlib.h at line 111,
something like: too many arguments.
What is wrong or is there any other ways to get random numbers?
Rasmus
rasmus.paivarinta@usa.net
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
: #include
: #include
: void main()
: {
: int rand;
: rand=random(10);
: cout<<rand;<br>
: }
: but DJGPP gives me an error in stdlib.h at line 111,
: something like: too many arguments.
random doesn't take any numbers as arguments. What you want is:
rand=random()%10;
which will give you a random number between 0 and 9 inclusively.
I highly recommend using the rand() function if you're interested in this working on several compilers. So instead, name your variable something else like x, and then:
x=rand()%10;
That's just a suggestion, though.
I would also like to call a fuction that generates
different numbers everytime I run the program.
I tried to just put randomize(); to the beginning, but DJGPP gave an error.
Rasmus
: different numbers everytime I run the program.
That will, unfortunately, mean that any bugs you run into may be unrepeatable. However, if you use rand() instead of random(), then use srand(value) to see rand() with a particular value at the start.
Here's a typical trick:
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run. */
srand( (unsigned)time( NULL ) );
different number everytime I run the program for
me, please?
Razze
: different number everytime I run the program for
: me, please?
: Razze
I just did:
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run. */
srand( (unsigned)time( NULL ) );
/*That, and for the actual random number:*/
int x=rand();
"time" can not be used as a function
Whats wrong?
Razze