From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from p-impout001.msg.pkvw.co.charter.net (p-impout002aa.msg.pkvw.co.charter.net [47.43.26.133]) by sourceware.org (Postfix) with ESMTPS id 5B4FD3857C40 for ; Wed, 29 Jul 2020 06:48:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B4FD3857C40 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=twcny.rr.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tlake@twcny.rr.com Received: from TOMHOMEPC ([67.255.1.251]) by cmsmtp with ESMTPA id 0fsdkEN6qv4w00fsekikcK; Wed, 29 Jul 2020 06:48:00 +0000 X-Authority-Analysis: v=2.3 cv=KaesTjQD c=1 sm=1 tr=0 a=SgDTZLGCaj4vW13Vpo4+rQ==:117 a=SgDTZLGCaj4vW13Vpo4+rQ==:17 a=DAwyPP_o2Byb1YXLmDAA:9 a=-xPLxyjo9AIjybqvnRIA:9 a=4UCefuqY7h1ak7vm:21 a=9dq7j3tub2JQ4TyR:21 a=CjuIK1q_8ugA:10 a=yMhMjlubAAAA:8 a=SSmOFEACAAAA:8 a=QQPj2NHHmCakTGp9gc4A:9 a=gKO2Hq4RSVkA:10 a=UiCQ7L4-1S4A:10 a=hTZeC7Yk6K0A:10 a=frz4AuCg-hUA:10 From: To: Subject: gfortran rand() not working properly? Date: Wed, 29 Jul 2020 02:47:58 -0400 Message-ID: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZldA2wSA7n7KQfQDaSJjBHC6acEw== Content-Language: en-us X-CMAE-Envelope: MS4wfKdO6kyz3t0HBKfwHwfRSc9mDUXC/QI4fynoG8CvLLjCVSUtoluSAKhZ5DzwK62dEjHnLkl1T8jYu8VPC/0OJZLb2MJSXUBn77ysarYAZ8ACTW+/r7Sc IHxmHRgLmz6g/kqxShQatVe0qPYIYc4Qm7YYsQAmf0tdojNZm7UcnrzD X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50, HTML_MESSAGE, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jul 2020 06:48:03 -0000 In the program below, the variable x is always a tiny number close to 0. It never gets to be more than about 1e-314. Variable y does get the whole range of rand() (0 - .9999999) This leads to all estimates of PI being 4.00000. If I add another variable t by uncommenting the line t=rand(), then t is incorrect but both x and y get the full range of rand() and the program works OK. I'm using the 64-bit version of gfortran with MSYS2-64 on Win 10. ! Program to compute Pi using monte carlo methods program monte_pi implicit none integer niter,i,j integer seed real*4 count real *8 x,y,pi(100),z,t real*8 rand ! initialize random numbers seed = 35791246 call srand (seed) do j= 1,100 niter = niter+100 count =0 do i=1,niter ! t = rand() x=rand() y=rand() z= x*x +y*y if (z .le. 1) count =count+1 end do pi(j)= count/niter*4. write(*,10) niter,pi(j) 10 format('Number of trials is: 'i5,' estimate of pi is:',f8.5) end do end