| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: [C] Moderator, schmoderator.. |
From: Bob Stout
On Sat, 22 May 2004, Bruce D. Wedding wrote:
> Just my .02 cents. I'm here to talk about C programming. It seems to
> me we have like 5 or so active participants. I don't guess I even
> understand the need. Let's talk C. Anyone know any published
> statistics on the MSVC standard library rand() function?
TTBOMK, it hasn't changed since the days of MSC 4.0. If that's true, it's
pretty good, but, IIRC, it could be improved by some of the versions in
SNIPPETS. It's not even that hard to test, though. Building a timed test
case using the built-in rand() and randomize() functions could be done
quite easily using the functions in SNIPPETS, e.g...
----[ snip ]----
/*
** RANDTEST.C - Public domain demo by Bob Stout
**
** Simple test for your compiler's rand() function.
** Allows the user to specify the seed value and timeout on the command line.
** Returns number of samples analyzed, arithmetic mean, and standard
** deviation.
** Searching for repeated patterns is left as an exercise for the user.
**
** Compile and link with the following SNIPPETS functions:
** mathstat.c
** binsrch.c (used by mathstat.c)
** commafmt.c
** commflt.c
** strrev.c (only required for gcc)
**
** SNIPPETS headers required in addition to the obvious ones below:
** sniptype.h (used everywhere)
** binsrch.h (used by mathstat.h)
** round.h (used by numcnvrt.h)
** pi.h (used by numcnvrt.h)
** snip_str.h (only required for gcc)
*/
#include
#include
#include
#include
#include "mathstat.h"
#include "numcnvrt.h"
int main(int argc, char *argv[])
{
unsigned seed = 37; // Randomizing seed - primes are better
double timeout = 120.0; // Test time in seconds
time_t t0; // Start time
Stat_T data; // Collect statistics here
size_t N; // Sample counter
char numbuf[16]; // Used by commafmt()
switch (argc)
{
case 3:
timeout = strtod(argv[2], NULL);
case 2:
seed = (int)strtol(argv[1], NULL, 16);
case 1:
break;
default:
puts("Usage: RANDTEST [seed] | [seed timeout (secs)]");
return EXIT_FAILURE;
}
stat_init(&data, 0);
srand(seed);
fprintf(stderr, "Working");
for (t0 = time(NULL); (difftime(time(NULL), t0) < timeout) ||
(UINT_MAX == N); )
{
int datum = rand();
stat_add((double)datum, &data);
N = stat_count(&data);
/***************************************************************/
/* */
/* If desired, put code here to detect repeated sequences. */
/* */
/***************************************************************/
/*
** Provide periodic feedback to let 'em know we're not dead
*/
if (0 == (N % 1000))
{
fputc('.', stderr);
fflush(sterr);
}
}
commafmt(numbuf, 16, N);
printf("\n\nRANDTEST done (%s samples)\n", numbuf);
comma_float(stat_mean(&data), numbuf, 4);
printf(" mean = %s\n", numbuf);
comma_float(stat_stddevP(&data), numbuf, 4);
printf(" standard deviation = %s\n", numbuf);
return EXIT_SUCCESS;
}
----[ snip ]----
Oddly enough, I wasn't able to get it working with MSVC (I recently
reinstalled everything and something's wrong in my setup). However, I did
run quick tests with the Digital Mars (nee Symantec, nee Zortech) compiler
and the MinGW32 port of gcc. Results follow:
----[ snip - DMC output ]----
RANDTEST done (10,752,906 samples)
mean = 16,386.4825
standard deviation = 7,736,876.6551
----[ snip - GCC output ]----
RANDTEST done (2,163,615 samples)
mean = 16,384.2081
standard deviation = 323,139.8046
----[ snip ]----
Obviously, quite crude and of dubious value, but a potentially useful starting point.
-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/ Web graphics development:
http://Image-Magicians.com/ Software archives:
http://snippets.snippets.org/
c.snippets.org/ cpp.snippets.org/ java.snippets.org/
d.snippets.org/ python.snippets.org/ perl.snippets.org/
dos.snippets.org/ embedded.snippets.org/ apps.snippets.org/
Audio and loudspeaker design:
http://LDSG.snippets.org/ http://www.diyspeakers.net/
--- BBBS/LiI v4.01 Flag-5
* Origin: Prism's_Point (1:261/38.1)SEEN-BY: 633/267 270 @PATH: 261/38 123/500 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.