Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | JohnF <john@please.see.sig.for.email.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: portable rand/srand across linux,windows,etc |
| Date | 2011-11-15 13:46 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <j9tqfg$cvd$1@reader1.panix.com> (permalink) |
| References | <j9tngi$fm9$1@reader1.panix.com> <0.cb82fea6f5be8eb86b9f.20111115131446GMT.878vnhttmh.fsf@bsb.me.uk> |
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote: > JohnF <john@please.see.sig.for.email.com> writes: >> Sorry if the wrong ng (please suggest another). >> I'm looking for robustly portable stdlib entry points >> for rand()/srand() (e.g., or random()/srandom()), >> particularly across linux gcc and windows >> mingw and djgpp (and ms compilers). >> That is, I want to distribute one source, without >> a lot of pesky #ifdef's, to compile on all platforms. >> Would also be nice if portable across everything >> else from free/netbsd to vms/dec C, too, but linux >> and windows are the biggies. Google shows various >> occasional complaints about rand stuff not compiling and/or >> not working on windows. I don't need anything particularly >> good -- just naked eye random, so to speak. And if it's >> easier to just cut-and-paste source from Numerical Recipes, >> I'm okay with that, too. > > rand and srand are documented in the C standard (and not only the most > recent -- they date back to C90) so they are amongst the most portable > functions you could call. I can't imagine that there's a Windows C > implementation without these (but I've been surprised before by > Windows). > > If you end up cut-and-pasting code, search the archives of this group > for KISS. George Marsaglia (sadly no longer with us) has posted several > highly efficient PRNGs with very long periods here. He was not a C > expert, but there have been followups that have correctly portability > issues where they've been spotted. Here's a reference to one: > Message-ID: <4dbd6e9c$0$12957$892e0abb@auth.newsreader.octanews.com> 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). 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. -- John Forkosh ( mailto: j@f.com where j=john and f=forkosh )
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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