Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #13426

Re: portable rand/srand across linux,windows,etc

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: portable rand/srand across linux,windows,etc
Date 2011-11-15 14:09 -0800
Organization None to speak of
Message-ID <lnsjlp11i3.fsf@nuthaus.mib.org> (permalink)
References <j9tngi$fm9$1@reader1.panix.com> <0.cb82fea6f5be8eb86b9f.20111115131446GMT.878vnhttmh.fsf@bsb.me.uk> <j9tqfg$cvd$1@reader1.panix.com>

Show all headers | View raw


JohnF <john@please.see.sig.for.email.com> writes:
[...]
> Thanks, Eric and Ben. Yeah, I'd already distributed source using
> srand()/rand(), and then came across a few google complaints about
> mingw not having them. So I thought I'd double-check while the fan
> was still clean (no problem emails yet).

I'm skeptical of such complaints.  For example, the following program
compiles and executes with no errors or warnings under MinGW:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
    srand(time(NULL));
    printf("%d\n", rand());
    return 0;
}

Admittedly I'm using a quite recent version of MinGW, but I woudn't
expect older versions to have any problems with this either.

My best guess is that somebody tried to use srand() and/or rand()
without the required "#include <stdlib.h>".

>                                          To cut-and-paste, by the way,
> even my K&R 2nd ed (also, sadly, just recently no longer with us)
> has a quick-and-dirty 10-line stdlib version on pg.46 that I probably
> would've used. So it seems pretty standard even back to then.

The 2nd edition of K&R is based on the 1989 ANSI C standard (which is
also, in effect, the 1990 ISO C standard).  You're not likely to find a
C implementation (at least a hosted implementation) that doesn't support
srand() and rand() in the manner required by the standard.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

portable rand/srand across linux,windows,etc JohnF <john@please.see.sig.for.email.com> - 2011-11-15 12:55 +0000
  Re: portable rand/srand across linux,windows,etc Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 08:01 -0500
  Re: portable rand/srand across linux,windows,etc Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-15 13:14 +0000
    Re: portable rand/srand across linux,windows,etc JohnF <john@please.see.sig.for.email.com> - 2011-11-15 13:46 +0000
      Re: portable rand/srand across linux,windows,etc Keith Thompson <kst-u@mib.org> - 2011-11-15 14:09 -0800
        Re: portable rand/srand across linux,windows,etc JohnF <john@please.see.sig.for.email.com> - 2011-11-16 03:45 +0000
          Re: portable rand/srand across linux,windows,etc Keith Thompson <kst-u@mib.org> - 2011-11-15 20:11 -0800

csiph-web