Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Genarating random number between 0 to 10

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

New User


Joined: 22 Apr 2008
Posts: 5
Location: Chennai

PostPosted: Tue Mar 03, 2009 10:13 am    Post subject: Genarating random number between 0 to 10
Reply with quote

Hi,

Could someone help me in generating a random number between 0 to 10.

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

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Mar 03, 2009 10:59 am    Post subject:
Reply with quote

Hello,

You need to provide more info for someone to properly answer.

Where/how will this number be used?
Back to top
View user's profile Send private message
dsarlie
Currently Banned

New User


Joined: 22 Apr 2008
Posts: 5
Location: Chennai

PostPosted: Tue Mar 03, 2009 11:35 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

You need to provide more info for someone to properly answer.

Where/how will this number be used?


Hi,

I have a field in my program wherein I have to generate the random telephone number and the number should be between 0 to 9

For my other purpose of generating random between 100 I used the following code and it working for pulling the records

Code:
01  DATE-AND-TIME-FIELDS.                                   
    03  WS-DATE                PIC 9(06)  VALUE ZEROES.     
                                                             
    03  WS-DATE-R REDEFINES WS-DATE.                         
        05 WS-YY       PIC 99.                               
        05 WS-MM       PIC 99.                               
        05 WS-DD       PIC 99.                             
                                                           
    03  WS-TIME                PIC 9(08)  VALUE ZEROES.     
                                                           
    03  WS-TIME-R REDEFINES WS-TIME.                       
        05 WS-HR       PIC 99.                             
        05 WS-MIN      PIC 99.                             
        05 WS-SEC      PIC 99.                             
        05 WS-HUN      PIC 99.                             
                                                           
01  RANDOM-NUM-GENERATER-FIELDS.                           
    03  MULTIPLIER             PIC 9(05)  VALUE 16807.     
    03  MODULUS                PIC 9(10)  VALUE 2147483646.
    03  QUOTIENT               PIC 9(06)  VALUE 127736.     
    03  REMDER                 PIC 9(04)  VALUE 2836.       
    03  LO-NUM                 PIC 9(06)  VALUE ZEROES.     
    03  HI-NUM                 PIC 9(06)  VALUE ZEROES.     
    03  SEED                   PIC S9(10) VALUE ZEROES.     
    03  UNIFORM                PIC 9V99   VALUE ZEROES.     
    03  RANDOM-NUMBER          PIC 9(03)  VALUE ZEROES.     
                                                             
                                               
*****************************************************         
0100-INITIALIZE.                                             
    OPEN   INPUT  ACCOUNT-FILE                               
           OUTPUT RANDOM-FILE.                               
    ACCEPT WS-DATE FROM DATE.                               
    ACCEPT WS-TIME FROM TIME.                               
**** GENERATE A SEED FOR THE RANDOM NUMBER GENERATER ******   
    COMPUTE SEED = ((WS-MM * WS-DD * WS-YY) +                   
                    (WS-HR * WS-MIN * WS-SEC * WS-HUN) + 1).   
    DISPLAY '       '.                                         

**************************************************
0300-GENERATE-RANDOM-NUMBER.                                     
    DIVIDE SEED BY QUOTIENT GIVING HI-NUM REMAINDER LO-NUM       
    COMPUTE SEED = (MULTIPLIER * LO-NUM) - (MULTIPLIER * HI-NUM)
    IF SEED < 1                                                 
       ADD MODULUS TO SEED                                       
    END-IF                                                       
    COMPUTE UNIFORM = (SEED / MODULUS)                           
    COMPUTE RANDOM-NUMBER = (UNIFORM * 100).                     

***************************************************


For generating telephone number it is not working out.

Thanks
Jeba
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Mar 04, 2009 2:45 am    Post subject:
Reply with quote

Hello,

Quote:
For generating telephone number it is not working out.
What does this mean? What happens?

How long is the telephone number? Depending on what you have already tried, you might try to generate the entire phone number instead of single digits. Or break the phone number into multiple pieces. . .

Is there some reason the number needs to be random? Possibly a series of sequential numbers could suffice?

You might also look here for the RANDOM function:
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3lr40/7.1.38?
Back to top
View user's profile Send private message
himanshupant

New User


Joined: 21 Mar 2007
Posts: 46
Location: India

PostPosted: Fri Mar 27, 2009 2:43 pm    Post subject: Random number
Reply with quote

Hi

I need random generator for a 6 digit number.

My requirement is that there is a VSAM file with say key as

branch , account , date and sequence number ( packed 3 bytes )

I need to change the branch account ( B1 A1 )for few accounts to some other branch account combination( say B2 A2) .

Now it is possible that if there was a record as

B1 A1 Date Seq1

after conversion to

B2 A2 Date Seq1 might give non unique records( because of the sequence number) which would cause the job to fail.

In these cases , I would need to re-generate a random sequence number and populate my record and then change the B1 A1 to B2 A2
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10276
Location: italy

PostPosted: Fri Mar 27, 2009 3:17 pm    Post subject: Reply to: Genarating random number between 0 to 10
Reply with quote

look at Your cobol manual and check for the RANDOM function
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 SMTP the current generation number of... Jyothi Kulunde JCL & VSAM 4 Thu May 04, 2017 4:08 pm
No new posts Edit large number of datasets (QSAM) zh_lad TSO/ISPF 3 Tue Apr 04, 2017 6:08 pm
No new posts how to mask the phone number kumarinfy DB2 4 Mon Apr 03, 2017 5:23 pm
No new posts what is meaning of the number in dcl Martylin PL/I & Assembler 2 Thu Mar 09, 2017 7:18 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us