Xref: news2.mv.net comp.lang.c:66634 comp.os.msdos.djgpp:3483 From: Shawn Hargreaves Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: Use of random Date: Sun, 5 May 1996 20:14:27 +0100 Organization: The University of York, UK Lines: 29 Message-ID: References: <4mikhp$pa5 AT frodo DOT smartlink DOT net> NNTP-Posting-Host: tower.york.ac.uk Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <4mikhp$pa5@frodo.smartlink.net> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp > To test out my radix_bit_sort function, I've been trying to generate a > list of random numbers to sort, and then sort them. The list is rather > long, 4000, and I'd like it to be ints, but I can' seem to get it! The > program compiles and runs without error, but it gives me #s far larger > than integers when I print out some results. I'm using DJGPP v2. How big is "larger than integers"? Remember that DJGPP is a 32 bit compiler. An integer can hold numbers up to 2^31, and that is pretty big :-) If you want to limit the number returned by rand() to a specific range, try the mod operator, eg. for an integer from 0 to 99, use rand()%100. > clock(); /* Initialize the clock */ > (int *)ticks = clock(); > srand(ticks); I don't think that will do what you were intending it to. If I'm not mistaken, the first time you call clock() it will zero the counter, and later calls will return elapsed time since the first call. Calling it twice in a row like that will almost always return zero, or some other very small number. A better approach would be to read the system time (by calling time()) and use that as your seed. /* * Shawn Hargreaves. Why is 'phonetic' spelt with a ph? * Check out Allegro and FED on http://www.york.ac.uk/~slh100/ */