Thread View: comp.sys.transputer
6 messages
6 total messages
Started by cca04 P.J. Mitchell
Mon, 23 Jul 1990 13:11
Random numbers
Author: cca04 P.J. Mitchell
Date: Mon, 23 Jul 1990 13:11
Date: Mon, 23 Jul 1990 13:11
18 lines
1330 bytes
1330 bytes
I am using Meiko's mf77 and it doesn't come with a library of C-like functions such as chdir, chown, mkdir etc. Therefore I have been writing a small library of fortran wrappers for these routines to ease calling them from fortran. My problem is that C has the two routines srand and rand. The latter returning an integer in the range 0-32767 (0 -> (2^15)-1). If I am to maintain compatibility with other unix fortrans then I have to make rand, drand and irand which are 31, 31 and 63 bits respectively. How do I generate this accuracy from the 15 bit C rand routine that the Sequent man pages say is used ? Any help netters ? -- --Paul Mitchell (CMA N.Cheshire, DoD#0145) | Computer Centre, JANET: cca04@uk.ac.keele.seq1 | University of Keele, Keele, USENET: cca04@seq1.keele.ac.uk@nss.cs.ucl.ac.uk | Staffordshire, ST5 5BG, U.K. BITNET: cca04%seq1.keele.ac.uk@ukacrl | 0782 - 621111 ext 3302
Re: Random numbers
Author: Richard A. O'Keefe
Date: Tue, 24 Jul 1990 06:46
Date: Tue, 24 Jul 1990 06:46
16 lines
1265 bytes
1265 bytes
In article <483@keele.keele.ac.uk>, cca04@.uk.ac.keele (P.J. Mitchell) writes:
> How do I generate this accuracy from the 15 bit C rand routine that
> the Sequent man pages say is used?
Don't.
Check "man random" to see if you have the BSD random number generator
and "man drand48" to see if you have the AT&T random number generator.
Check books like "Numerical Recipes" for random number generators and
look in back issues of journals like "Applied Statistics".
Look in Knuth Vol 2 ("Numerical Recipes" provides Fortran code for at
least one of the methods he describes, one of the better ones).
--
Science is all about asking the right questions. | ok@goanna.cs.rmit.oz.au
I'm afraid you just asked one of the wrong ones. | (quote from Playfair)
Re: Random numbers
Author: Peter S. Shenkin
Date: Tue, 24 Jul 1990 13:38
Date: Tue, 24 Jul 1990 13:38
22 lines
1656 bytes
1656 bytes
In article <483@keele.keele.ac.uk> writes: >My problem is that C has the two routines srand and rand. The latter >returning an integer in the range 0-32767 (0 -> (2^15)-1). If I am C has no such thing. UNIX has such things. Rand and srand are outdated relics of the PDP-11 era, and have been replaced on almost all (?) UNIX systems by random and srandom, which return 32-bit values. If your UNIX system supports these, use them and avoid the problem! In any case, even on 32-bit UNIX machines when called from C, rand returns random values only in the 16 high-order bits, so when using these functions even from C it is necessary to do a 16-bit shift to the "right". Without this, the sequence of numbers returned alternates strictly between even and odd (at least it did on a VAX running ULTRIX) -- scarcely pseudorandom behavior! -P. ************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb************************** Peter S. Shenkin, Department of Chemistry, Barnard College, New York, NY 10027 (212)854-1418 shenkin@cunixc.cc.columbia.edu(Internet) shenkin@cunixc(Bitnet) ***"In scenic New York... where the third world is only a subway ride away."***
Re: Random numbers
Author: Marianne Mueller
Date: Tue, 24 Jul 1990 23:45
Date: Tue, 24 Jul 1990 23:45
2 lines
674 bytes
674 bytes
See also Park & Miller, "Random Number Generators: Good Ones Are Hard to Find", CACM, Vol 31, No 10, Oct 1988, 1192-1201.
Re: Random numbers
Author: Rick Schubert
Date: Tue, 31 Jul 1990 19:30
Date: Tue, 31 Jul 1990 19:30
34 lines
2384 bytes
2384 bytes
In <1990Jul24.133823.6608@cunixf.cc.columbia.edu> shenkin@cunixf.cc.columbia.edu (Peter S. Shenkin) writes: >In article <483@keele.keele.ac.uk> writes: >>My problem is that C has the two routines srand and rand. The latter >>returning an integer in the range 0-32767 (0 -> (2^15)-1). If I am >C has no such thing. UNIX has such things. Rand and srand are outdated >relics of the PDP-11 era, and have been replaced on almost all (?) UNIX >systems by random and srandom, which return 32-bit values. If your UNIX >system supports these, use them and avoid the problem! I don't know if all the C people have stopped reading this newsgroup, or if they are asleep, or just don't care, but I've waited about a week and haven't seen anyone refute this. What you say about rand() and srand() is just not true. They certainly are a part of C. That is they are a part of ANSI C and are a part of many (most? all?) pre-ANSI C libraries. And they haven't been replaced on any UNIX systems that I know of; in fact, the 3 UNIX systems that I just checked (5.2, 5.3, and 5.4) all have rand()/srand() but none of them have random() (perhaps random() is BSD). >In any case, even on 32-bit UNIX machines when called from C, rand returns >random values only in the 16 high-order bits, so when using these functions >even from C it is necessary to do a 16-bit shift to the "right". Without >this, the sequence of numbers returned alternates strictly between even >and odd (at least it did on a VAX running ULTRIX) -- scarcely pseudorandom >behavior! It's true that most versions of rand() return values in the range 0-32767, even on 32-bit machines, but they are in the low-order bits. If VAX/ULTRIX returns them in the high-order bits, then either it's broken or you've messed something up (or are confused about left/right vs. high/low). -- Rick Schubert (rns@se-sd.sandiego.NCR.COM)
Re: Random numbers
Author: William Rosencranz
Date: Thu, 02 Aug 1990 07:24
Date: Thu, 02 Aug 1990 07:24
35 lines
2353 bytes
2353 bytes
In article <3618@se-sd.SanDiego.NCR.COM> rns@se-sd.SanDiego.NCR.COM (Rick Schubert) writes:
>In <1990Jul24.133823.6608@cunixf.cc.columbia.edu> shenkin@cunixf.cc.columbia.edu (Peter S. Shenkin) writes:
>>In article <483@keele.keele.ac.uk> writes:
>>>[about srand and rand]
>>C has no such thing. UNIX has such things. Rand and srand are outdated
>I don't know if all the C people have stopped reading this newsgroup, or
>if they are asleep, or just don't care, but I've waited about a week and
still here, and even awake!
>haven't seen anyone refute this. What you say about rand() and srand() is
>just not true. They certainly are a part of C. That is they are a part of
>ANSI C and are a part of many (most? all?) pre-ANSI C libraries. And they
according to harbison and steele at least, they are not really part of
the language, per se, but rather are part of a set of libraries, actually
"facilities", deemed standard by the ANSI C. if they were actually
part of the SYNTAX of the language, they would be listed in with the
reserved words (like for, if, else, while, etc). this is really
semantics and splitting hairs, however. C, unlike fortran, does not
provide language support for i/o, for example, but does provide i/o
pretty much "standard" via the libraries. ANSI C just makes things
like printf work the same with compliant libraries. i'd say that if
posix sez something about things like printf and rand, then it might
be stronger to say that they are more "unix" artifacts than C, if you
look at it that way. my green book is in the office so i can't really
answer this...
-bill
rosenkra%c1yankee@convex.com
(my opinion, not my employer's...)
Bill Rosenkranz |UUCP: {uunet,texsun}!convex!c1yankee!rosenkra
Convex Computer Corp. |ARPA: rosenkra%c1yankee@convex.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads