🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by David Charlap Mon, 04 Jan 1993 21:07
Bug in gcc's rand() function.
#1577
Author: David Charlap
Date: Mon, 04 Jan 1993 21:07
26 lines
1122 bytes
When the stdlib.h rand() function is called, the sequence is
repeatable, mod 8.

For example, the following code:

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

	main() {
	  int x;

	  for (x=0; x<100; x++)
	    printf ("%d   ", rand() % 8);
	}

always produces the following repeating sequence:

	6   7   4   5   2   3   0   1

I have tested it on the OS/2 2.0 port of gcc and the Dec-Ultrix
version, and I get the same result in both cases.
-- 
  |)  David Charlap          | .signature confiscated by FBI due to
 /|_  dic5340@hertz.njit.edu | an ongoing investigation into the
((|,)                        | source of these .signature virusses
 ~|~
Re: Bug in gcc's rand() function.
#1587
Author: David Charlap
Date: Tue, 05 Jan 1993 21:42
33 lines
1824 bytes
In article <1993Jan4.210729.28287@njitgw.njit.edu> dic5340@hertz.njit.edu (David Charlap) writes:
>When the stdlib.h rand() function is called, the sequence is
>repeatable, mod 8.
>
>For example, the following code:
>
	[deleted]
>
>always produces the following repeating sequence:
>
>	6   7   4   5   2   3   0   1
>
>I have tested it on the OS/2 2.0 port of gcc and the Dec-Ultrix
>version, and I get the same result in both cases.

Thanks to all those who responded - you can stop the e-mail now!

To summarize, the problem isn't in gcc, but in the C library.  Since I
work primarilly with OS/2, I am used to the non-Unix convention of
shipping the library with the compiler, so I assumed both to be the
same.  The OS/2 port of gcc includes a port of the library, and I
mistakenly thought that this was a part of the gcc distribution.

Fortunately, in addition to porting the rand() bug, the author also
ported the random() function which avoids the bug.  So there's to
further problem.

Thanks to everyone who responded for helping me figure this out.
-- 
  |)  David Charlap          | .signature confiscated by FBI due to
 /|_  dic5340@hertz.njit.edu | an ongoing investigation into the
((|,)                        | source of these .signature virusses
 ~|~
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