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 Numbers distributed evenly without pattern

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
grvtomar

New User


Joined: 29 Apr 2015
Posts: 7
Location: Sri Lanka

PostPosted: Sat Jul 21, 2018 3:34 am    Post subject: Random Numbers distributed evenly without pattern
Reply with quote

Hi Mainframers,

I want to create random numbers using COBOL. These numbers should have the properties
1. It should be random
2. Evenly distributed
which means If It of 4 digits
0001- 999 . - around 10%
1001- 1999 . around 10%
2001- 2999 . around 10%
..... - ......
and so on..

3. It should not have some pattern

I am not sure if it is possible with COBOL. I tried to do it with Random function+Db2 nano-seconds(seed). I got the purely random numbers. But I am not able to achieve point 2 and point 3 using that. Any approach in Cobol would be helpful icon_smile.gif

Many Thanks
Back to top
View user's profile Send private message

sergeyken

Active User


Joined: 29 Apr 2008
Posts: 365
Location: Maryland

PostPosted: Sat Jul 21, 2018 4:29 am    Post subject:
Reply with quote

All known RANDOM functions do provide even distribution of values, and no obviously visible pattern.
I recommend not to make simple things to become very complex.
Back to top
View user's profile Send private message
grvtomar

New User


Joined: 29 Apr 2015
Posts: 7
Location: Sri Lanka

PostPosted: Sat Jul 21, 2018 6:13 am    Post subject:
Reply with quote

Sorry, my question was not clear I guess..
SO
Random Function used to generate two random-digits series
Randoms digits-1 Random Digits-2
xxxx yyyy
gggg hhhh
.....
....
...
(1000 numbers for each random-digits)

Both the series is having similar pattern and non-even distributing.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8400
Location: Dubuque, Iowa, USA

PostPosted: Sat Jul 21, 2018 7:20 am    Post subject: Reply to: Random Numbers distributed evenly without pattern
Reply with quote

Quote:
Sorry, my question was not clear I guess..
No, you are not being clear at all.

FUNCTION RANDOM in COBOL generates a pseudo-random sequence of values from a rectangular distribution (IBM's words, not mine). What that means is that if you THINK you are seeing patterns or non-uniformly distributed values, you need to review what you are doing:
- are you using a seed value for FUNCTION RANDOM?
- are you converting the returned values to your value range correctly?
- what does your code look like?

Properly used, FUNCTION RANDOM in COBOL will return uniformly distributed values that are pseudo-random (named this because computers cannot provide truly random values). So if you're not seeing this, you have made some mistake in your use of the function.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 2030
Location: NY,USA

PostPosted: Sat Jul 21, 2018 5:39 pm    Post subject:
Reply with quote

Try using one or many sequence objects in db2. Your DbA should help you if you at all approach him.
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 194
Location: Toronto, ON, Canada

PostPosted: Wed Aug 15, 2018 9:17 pm    Post subject:
Reply with quote

Below shows sample code to call the Language Environment subroutine to generate a random number between 0 and 1 as a double floating point.
Code:
05 W-CEERAN0-SEED                PIC S9(08) COMP-5 VALUE 0.
05 W-CEERAN0-NUM                 COMP-2.

CALL 'CEERAN0'
USING W-CEERAN0-SEED
      W-CEERAN0-NUM
      OMITTED
END-CALL

If you want a 4 digit number then multiply the result by 10000 and then move to an PIC 9(4) field.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 2030
Location: NY,USA

PostPosted: Wed Aug 15, 2018 11:23 pm    Post subject:
Reply with quote

That's good to know. here is the link for further details.
CEERAN0—Calculate uniform random numbers
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    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 Incorrect output when trying to add n... monica1 PL/I & Assembler 10 Fri Jan 13, 2017 5:02 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm

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