www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/10/18:21:39

Date: Fri, 10 Apr 1998 18:19:36 -0400 (EDT)
From: Jude DaShiell <dashiell AT clark DOT net>
To: djgpp AT delorie DOT com
Subject: fighting djgpp libraries
Message-ID: <Pine.GSO.3.96.980410181021.6181A-100000@shell.clark.net>
MIME-Version: 1.0

All I was trying to do was to use clock() to seed srandom() since
I think I've maybe figured out a technique for improving random number
generation for programmers using gcc at least.
One thing I noticed was that re-seeding of random number generators
happened very
predictibly in code I've read.
I asked myself would any measureable effect come out of randomizing
re-seeding?
To that end I tried writing the following code.  I think it's commented
pretty well.
Here's the source code below, I'd like to know how to resolve the
conflicts;
and if any readers are interested and they can get this working I'd be
interested to
know if it made any improvements for applications in which they might try
this code.
If this does make any improvements those who can download it are free to
use it
to the fullest extent they'd like.

/*
 * program written for improving use of pseudorandom numbers re-seeding of
 * random numbers happens too predictably in many programs.  It's possible to
 * randomize when re-seeding happens too. language: djgpp and probably power
 * C. programmer: j.t. dashiell. date written: April 3, 1998. date modified:
 * April 6, 1998, 
 */

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>

int 
main(void)
	double          modf(double x, int *p);
clock_t 
clock(void);
long 
random(void);
{
	int             qr, si, sw = 0;
	printf("enter quantity of random numbers to generate: ");
	scanf("%d", &qr);
	for (k = 0; k < qr; k++) {
		/* start main loop for using random numbers */
		if (sw < 1) {
			/* start seeding loop */
			srandom(clock());	/* seed random number
						 * generator with time value */
			si = random() % qr;	/* modulus random value so
						 * si<=qr */
			sw++;	/* increment sw /* end seeding loop. */
		}
		...;
		put what would have been original code here.
		/*
		 * I can understand gcc dying on line above, but conflicts
		 * before this area of code in #include files I don't
		 * understand 
		 */
		/* I'm using gcc 2.721 now. */
		                si--;	/* decrement re-seed counter */
		qr--;		/* decrement main loop counter */
		if (si < 0) {
			/* test for new seed time */
			sw--;
		}
		/* end main loop */
	}
	exit(0);		/* end program */
}



Jude <dashiell AT clark DOT net>

- Raw text -


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