Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon From: gordon@osiris.cso.uiuc.edu (John Gordon) Newsgroups: comp.lang.c Subject: Re: I'm confused about this Keywords: getpid(), srand Message-ID: <1990Nov21.025459.22201@ux1.cso.uiuc.edu> Date: 21 Nov 90 02:54:59 GMT References: <3945@vela.acs.oakland.edu> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 19 jmwojtal@vela.acs.oakland.edu (Wojo) writes: >I got this C program and this part I don't understand: >int getpid(); >long now; >now = time(&now) / rand(); >srand(getpid() + (int)((now >> 16) + now + time(&now))); >What does "srand" do to be exact? It doesn't bring a value back? >"getpid()" is declared, but the function is not in the program. srand() "seeds" the random-number generator, enabling it to produce numbers that are more random than if you hadn't seeded it. getpid() gets the process' ID number. This is usually a fairly good choice for a random number. So, the random-number generator is seeded with another random number. This ensures very random results.