× 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.



The random number should be a value between zero and 1 (if this API
doesn't do that, ignore what I'm saying). All you have to do is multiply
the result by your max and you'll get a value in that range.

Matt

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Douglas Palme
Sent: Friday, March 16, 2007 10:41 AM
To: 'RPG programming on the AS400 / iSeries'
Subject: Random Numbers

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 ...

Replies:

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.