www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/06/20:26:35

From: Michael Smith <emmenjay AT zip DOT com DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: random() error?
Date: Wed, 07 Apr 1999 01:59:35 +0900
Organization: Emmenjay Consulting
Lines: 49
Message-ID: <370A3D77.51EE@zip.com.au>
References: <7e1lhb$qkt$1 AT news DOT snowcrest DOT net>
NNTP-Posting-Host: 61.8.18.225
Mime-Version: 1.0
X-Mailer: Mozilla 3.0Gold (Win95; I; 16bit)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019