🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.games
Article #2454

Re: Battleship source for Unix w/curses

#2454
From: Gregory Smith
Date: Wed, 26 Mar 1986 17:21
26 lines
1949 bytes
In article <4336@dartvax.UUCP> davidk@dartvax.UUCP (David C. Kovar) writes:
>>> My problem, however, is with the pattern that the ships are set up in.  
>>> The first time you play the game (every time you play it) the pattern that
>>> the ships are in is identical.

>>That's easy. Just insert a "srand(getpid());" somewhere in the beginning
>>of the program, before the first "rand" call.

>That'll still have the same problem. getpid() will return the same pid
>each time the same user runs it, thus you would get the same seed for
>rand each time. Try srand(time()); instead.

No it won't. Every time you run something, a new process ID is assigned, no
matter what you are running. getpid is get-process-id, not get-user-id.
If you do srand(getpid()) twice in the same
execution, you will get the same pid each time of course. That's why I said
in my earlier posting that this should be done _exactly_once_, i.e. if the
user wants to play again, don't call srand again!

by the way:	srand( (int) getpid ());	/* srand wants an int and */
or		srand( (int) time() );	/* time() and getpid() return longs */

-- 
"No eternal reward will forgive us now for wasting the dawn" -J. Morrison
----------------------------------------------------------------------
Greg Smith     University of Toronto       ..!decvax!utzoo!utcsri!greg
Technical Details
Message-ID: <2407@utcsri.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
References: <314@drivax.UUCP> <9200033@uiucdcs> <4336@dartvax.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
From: greg@utcsri.UUCP (Gregory Smith)
Newsgroups: net.games
Subject: Re: Battleship source for Unix w/curses
Message-ID: <2407@utcsri.UUCP>
Date: Wed, 26-Mar-86 12:21:11 EST
Article-I.D.: utcsri.2407
Posted: Wed Mar 26 12:21:11 1986
Date-Received: Wed, 26-Mar-86 14:25:41 EST
References: <314@drivax.UUCP> <9200033@uiucdcs> <4336@dartvax.UUCP>
Reply-To: greg@utcsri.UUCP (Gregory Smith)
Organization: CSRI, University of Toronto
Lines: 26