Mail Archives: djgpp/1999/04/06/20:26:35
I don't think randomize() and random() are standard functions.  You
would be better with the portable srand() and rand() functions.
srand( time(NULL) );       // seed random number generator
for( j=0; j<52 ;j++ )      // for each card in the deck,
{    short k=rand()*52;    // pick another card @ random
// etc.
It's almost never a good idea to use a non-standard function when a
standard one will do.
Richard Lohuis wrote:
> 
> I'm having a problem with generating random numbers.
> 
> I'm taking a class on C++ OOB programming, the text & class are geared
> toward Borland Turbo C.  I finally had to get a copy just to make sure that
> some error I run into are mine. usually the case, but the following snippet
> runs on TC:
> 
> ;
> ;
> randomize();               // seed random number generator
> for( j=0; j<52 ;j++ )      // for each card in the deck,
> {    short k=random(52);   // pick another card @ random
>      Card temp=Deck[k];    // & swap them
>      Deck[j]=Deck[k];
>      Deck[k]=temp;
> }
> ;
> 
> It states: Error: too many arguments to function 'random()'
> pointing directly to "random(52)"
> In 'stdlib.h', the corresponding highlight is:
>     long random(void);
> Looks to me like it won't take an argument.
> beings I typed it out of the book I'm now confused, TC takes it, DJGPP
> won't.
> Thanks in advance,
> richhlo AT snowcrest DOT net
-- 
########################################################################
Michael Smith                                        emmenjay AT zip DOT com DOT au
Emmenjay Consulting Pty Ltd             http://www.zip.com.au/~emmenjay/
Computers *ARE* user-friendly.  You just need to be properly introduced.
- Raw text -