IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Genarating random number between 0 to 10


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 03, 2009 10:59 am
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
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

Moderator Emeritus


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

PostPosted: Wed Mar 04, 2009 2:45 am
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:
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Mar 27, 2009 3:17 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Increase the number of columns in the... IBM Tools 3
No new posts Random read in ESDS file by using RBA JCL & VSAM 6
Search our Forums:

Back to Top