× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I have been looking for a random number generator for RPG and found an
example on IBM's website.  I know that with other languages I can specify
that I want the random numbers that are generated to fall within a specified
range, IE: between 1 and 1000.

Here is the code that IBM suggested:

Fseedpf    uf   e             disk    usropn            
F                                                       
Frandpf    o    e             disk    usropn            
F                                                       
DTimes            c                   const(1000)       
Dfactor           c                   const(10000000000)
D                                                       
Dstdpacked        s             15p 5                   
Dstdint           s             10i 0                   
Dstddouble        s              8f                     
Dstdfc            s             12a                     
D                                                       
Drandnum_gen      pr                  extproc('CEERAN0')
Dpr_seed                              LIKE(stdint)      
Dpr_randum                            like(stddouble)   
Dpr_fc                                like(stdfc)       
D                                                    
Dcounter          s                   like(stdint)   
D                                                    
Dseednum          s                   like(stdint)   
D                                                    
Drandnum          s                   like(stddouble)
Dfeedbackcode     s                   like(stdfc)    
D                                                    
C                   open      seedpf                 
C                   open      randpf                                   
C                                                                      
C                   read      seedrec                                  
C                   eval      seednum = %rem(seedfld:factor)           
C                   for       counter = 1 by 1 to times                
C                   callp     randnum_gen(seednum:randnum:feedbackcode)
C                   eval      randfld = randnum                        
C                   write     randrec                                  
C                   endfor                                             
C                   eval      seedfld = seednum
C                   update    seedrec          
C                   close     randpf           
C                   close     seedpf           
C                   eval      *inlr = *on      

Maybe I am blinding myself here, but with using the C API, I do not see any
way of setting a range.

Has anyone else performed such an operation before? If so, how did you
specify the lower and upper range?
 




****************************************************************************
This transmission may contain information that is privileged,
Confidential and/or exempt from disclosure under applicable law.
If you are not the intended recipient, you are hereby notified that
any disclosure, copying, distribution, or use of the information
contained herein (including any reliance thereon) is STRICTLY
PROHIBITED. If you received this transmission in error, please
immediately contact the sender and destroy the material in its
entirety, whether in electronic or hard copy format. Thank you.
****************************************************************************


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.