Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
RANDOM Function in COBOL

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
swapnil781

New User


Joined: 29 Jul 2009
Posts: 10
Location: Bangalore

PostPosted: Tue Nov 15, 2016 6:17 pm    Post subject: RANDOM Function in COBOL
Reply with quote

Hi,

I am trying to write a new COBOL program that can estimate PI by simulating ‘Buffon’s needle’ experiment. I am trying to use the RANDOM function but not able to get the desired results. Requires help for more inputs on RANDOM function, I tried in the Manual but did not get the required help.

Inputs in pgm.
Distance-between- lines (eg. 100 for 100 mm.)
Needle-length (eg.40 for 40 mm)
Needle-drops (eg 1000 )

Buffons Needle formula Pi = 2 * L /(X * P)
To calculate the value 'P' I am using RANDOM function but not able to get the same.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1777
Location: Bloomington, IL

PostPosted: Tue Nov 15, 2016 6:25 pm    Post subject:
Reply with quote

Duplicate of thread on another board; locked.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Tue Nov 15, 2016 6:26 pm    Post subject: Reply to: RANDOM Function in COBOL
Reply with quote

Is this for IBM's contest? There was the exact same topic on the Beginner's and Student's Forum the other day. I will repeat my comments from that forum:

The Enterprise COBOL Language Reference manual tells you plenty about the seed for RANDOM:
The seed value can be whatever you want between 0 and 2147483645 (in COBOL 5.1).
The seed value is only needed for the first use of RANDOM; after that, if no parameter is passed to RANDOM the next value in the current sequence will be returned.
If you don't specify a seed value the first call, RANDOM uses zero.
For any given seed value, the pseudorandom sequence returned will be the same.

So for simplicity of testing you probably want to use a constant for the seed value; for your actual run(s) you probably want to use something that will vary (based on time, for example -- calculate seconds elapsed today / this week / this month or this year). Note that the value returned by RANDOM needs to be stored in a COMP-1 or COMP-2 variable since it represents a floating point value between 0 and 1.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us