RPGLE AS400

1355 pts.
Tags:
AS400 RPGLE
RPGLE
How to create 6 digit non repeating random number in rpgle as400?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here is a link toi an IBM site
Generating Random Numbers in ILE RPG Using the CEERAN0 API

http://www-01.ibm.com/support/docview.wss?uid=nas1f23d225573c211a186256a240067a3da

Discuss This Question: 36  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • pdsathishkumar
    ILE RPG Using the CEERAN0 API please may i know about CEERAN0 API.... i searched in Google, but i didn't get clear information... please give the abbreviation of CEERAN0 API...
    3,790 pointsBadges:
    report
  • philpl1jb
    Charlie Browne said: http://www-01.ibm.com/support/docview.wss?uid=nas1f23d225573c211a186256a240067a3da
    50,505 pointsBadges:
    report
  • pdsathishkumar
    i think the CEERAN0 is an application.. just i want to know that application.. thats all.... what purpose, we can use this application...
    3,790 pointsBadges:
    report
  • philpl1jb
    an API - CEERAN0 creates random numbers - used in game design and simulation.
    50,505 pointsBadges:
    report
  • 9783444184
    Hi Philpl1jb, i tried this program and found 1000 random number but but i require 6 digit non repeating no. like as 123456 instead off 235156 (wrong no)
    1,355 pointsBadges:
    report
  • TomLiotta
    like as 123456 instead off 235156 (wrong no) What you want seems to be six non-repeating digits. The API can give a random "number", but it will be your logic that takes that number and picks one of the digits from 0 through 9. Each digit will be stored in an array. Each new digit will be selected from the remaining digits that have not been used yet. Tom
    125,585 pointsBadges:
    report
  • 9783444184
    i have tried a program where user input 1 to 6 digits in display file and generate a six non-repeating digits randomly i am using array and store in input values in array. now i want to compare input values to my generated six non-repeating digits. what should i do please help.....
    1,355 pointsBadges:
    report
  • TomLiotta
    what should i do please help….. For me, the easiest thing to do would be to code a loop over one of the arrays. For each element of that array, perform a %lookup() over the other array to see if a match exists. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Confused, again as usual! I understand that you're generating 6 one digit numbers that do not match each other. And now you want to test to make sure that none of these digits match any of the 6 one digit unique numbers in the input? So random number 1-2-3-4-5-6 would fail since some digits match input number 6-4-2-0-9-8. I'm not real quick but 6 input digits and 6 generated digits that don't match .. 12 unique single digits, what numbering system are you using? Phil
    50,505 pointsBadges:
    report
  • 9783444184
    Hi Philpl1jb, i want 6 input from input screen like 1 2 3 4 5 6 and create a six digit number 123456 now i want a six digit non repeating random number which between 1 to 9 like 654321 but not 653541 like that if random number is correct then compare both number (input and random) are equal or not this is my requirement.....Sorry for the Confutation
    1,355 pointsBadges:
    report
  • TomLiotta
    Well, if you have two 6-digit numbers that cannot have digits that match in any position, you need at least base-12 to get 12 unique digits. So, it can't be possible that digits from the two numbers can't match each other. Therefore, matches must be important only for digits within a single 6-digit number. For that, you could simply have a 10-element binary array with all elements initialized to 0. When a digit is chosen, check to see if the corresponding element is 0 or 1. If it's 0, then set it to 1, and store the digit. But if the element is already 1, then discard the digit and generate a new on. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    no, I am more confused. if input is 1-2-3-4-5-6 generate number rule 1 - six digits cannot be duplicates generated number 7-7-8-9-2-3 violates rule 1 (two 7's) rule 2 -- input cannot equal generated number input number 1-2-3-4-5-6 generated number 1-2-3-4-5-6 violates rule 2 rule 3 -- no digit on input can match the same location on output 1-3-5-7-9-2 violates rule 2 because the first digit of the input (1) equals the first digit on the generated number (1) rule 4 -- Phil's guess total of generated digits cannot equal total of input digits input 1+2+3+4+5+6 = 21 generated number 6+5+4+3+2+1 = 21 which violates rule 4 rule 5 -- no digits of input can be used in output input 1-2-3-4-5-6 generate number 7-8-9-A-B-0 -- good answer in base 12 Which of these rules do you want? What other rules do you need to apply.
    50,505 pointsBadges:
    report
  • 9783444184
    Hi Philpl1jb, Good morning I explain you which rule i need 1-user input digits can't be duplicate like 1-2-3-2-4-5 wrong input (i coded already) 2-generated number can't be duplicate like 1-2-3-2-4-5 wrong number generate 3-input number and generated number if equal then successful. like (123456=123456)
    1,355 pointsBadges:
    report
  • philpl1jb
    Rule 2-generated number can’t be duplicate like 1-2-3-2-4-5 wrong number generate Good2 = *on for y= 1 to 5 for x = y+1 to 6 if G(y) =G(x); Good2 = *off endif; // Good2 will be *on for good case 3-input number and generated number if equal then successful. like (123456=123456) If I and G are the inputs .. perhaps Good3 = I = G or in the D specs DInputDS DS i 1s 0 dim 6 i6 1 6a DGenDS DS G 1s 0 dim 6 G6 1 6a Rule6 = I6 = G6; // on if match
    50,505 pointsBadges:
    report
  • philpl1jb
    or in the D specs
    D InputDS                   DS
    D  i                                        1s 0     dim 6
    D  i6                                   1 6a
    
    D GenDS                     DS
    D G                                        1s 0 dim 6
    D  G6                                  1 6a
    
    Then when you need to test rule6 use this code. Rule6 = I6 = G6; // on if match
    50,505 pointsBadges:
    report
  • 9783444184
    but how to generate number where maxno is 9 and min no is 1
    1,355 pointsBadges:
    report
  • philpl1jb
    Thought you were way past this point "i tried this program and found 1000 random number" Random number is probably coming back as a decimal between 0 and .9999 use the integer of multiping decimal by 9 and adding 1
    50,505 pointsBadges:
    report
  • 9783444184
    please post me code for that
    1,355 pointsBadges:
    report
  • philpl1jb
      
    H DFTACTGRP(*NO) ACTGRP('QILE')                         
                                                            
    d CEERAN0         PR                                    
    d seed                          10I 0                   
    d ranno                          8F                     
    d fc                            12A   options(*omit)    
                                                            
    d highno          s             10I 0 Inz(9)   ..//upper limit
     lowno           s             10I 0 Inz(1)        //lower limit
    
    d seed            s             10I 0 inz(0)            
    d rand            s              8F                     
    d range           s             10I 0                   
    d result          s             10I 0                   
                                                            
     /free                                                  
         range = (highno - lowno) + 1;                      
         CEERAN0( seed : rand : *omit );                    
         result = %int(rand * range) + lowno;            // this multilies the random number by 
          dsply result;                                                     // it expands it by the range snf sff loert
         return;                                            
     /end-free                 
    
    The field resu;t contaiin a random njmber bettweem' 1 and 30
    
    Phil
    50,505 pointsBadges:
    report
  • 9783444184
    yes i have this code but it always generate duplicate number ......
    1,355 pointsBadges:
    report
  • philpl1jb
    Ask clearer questions! You said that you could generate 1000 random numbers now you say you can't?
    50,505 pointsBadges:
    report
  • 9783444184
    [H DFTACTGRP(*NO) ACTGRP(’QILE’) d CEERAN0 PR d seed 10I 0 d ranno 8F d fc 12A options(*omit) d highno s 10I 0 Inz(9) ..//upper limit lowno s 10I 0 Inz(1) //lower limit d seed s 10I 0 inz(0) d rand s 8F d range s 10I 0 d result s 10I 0 /free dow count<6 ; range = (highno - lowno) + 1; CEERAN0( seed : rand : *omit ); result = %int(rand * range) + lowno; // this multilies the random number by dsply result; // it expands it by the range snf sff loert count+=1; return; /end-free ]
    1,355 pointsBadges:
    report
  • 9783444184
    when i run this it displayed duplicate number
    1,355 pointsBadges:
    report
  • philpl1jb
    I see a do while but no enddo???? Exch call to this program displays the same number .. or the 1 call displays 6 identical digits. The problem seems to be in the seed -- since it's 0 it will use system time Which should create a new value on each call. Since it's using system time and your loop is fairely tight, it might get the smae system time for all 6 digits result = %int(rand * range) + lowno; // this multilies the random number by seed = %int(rand * 123456 * count + count); // so you could use some process like this in the loop just after processing the first rand to generate the seeds for subsequent random numbers. Phil so in your loop seed will have a different value every time.
    50,505 pointsBadges:
    report
  • TomLiotta
    It's hard to tell what the problem is since there are multiple numbers that might be "duplicated" according to the rules that have been described. Try this version:
         H dftactgrp( *NO ) actgrp( *NEW ) indent( '  ' )
    
         D chk             s              1s 0 inz( 0 )
         D rnum            s              8f
    
         D i               s             10i 0
    
         D dup             s               n   dim( 9 ) inz( *off )
    
         D digit           s              1    dim( 6 ) inz
    
         D p_digit         s               *   inz( %addr( digit ) )
         D digits          s              6    based( p_digit )
    
         D random          pr                  extproc( 'CEERAN0' )
         D  seed                         10i 0 const
         D  randnbr                       8f
         D  fc                           12    options( *nopass )
          /free
           dsply 'Start:' ;
    
           for i = 1 to 6 ;
    
              dou dup( chk ) = *off ;
                 callp  random( 0 : rnum ) ;
                 chk =  rnum * 9 + 1 ;
              enddo ;
    
              dup( chk ) = *on ;
    
              dsply  chk ;
    
              digit( i ) = %char( chk ) ;
    
           endfor ;
    
           dsply digits ;
    
           *inlr = *on ;
           return ;
          /end-free
    If that works better, then we know what was being "duplicated. Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    Tom seed of zero --- wasn't that the latest problem? Phil
    50,505 pointsBadges:
    report
  • TomLiotta
    seed of zero — wasn’t that the latest problem? That's what I can't determine. Is it that each new set-of-6 is the same as the previous set-of-6? Or is it that digit 1-of-6 is a duplicate of digit 3-of-6 or 5-of-6 or whichever? That is, is the 6-digit number 135497 generated the first time and also the second time? Oops! "Duplicated" sequence. That could be a seed problem. Or is it that digits are like 1-3-5-3-5-1? Oops! No good. "Duplicated" digits! Tom
    125,585 pointsBadges:
    report
  • 9783444184
    one more thing is there i have indicator in every input field and i am checking through loop for two or more fields are same now how to find both indicator if two fields are same. example 1 2 2 3 5 6 and indicators are 20 21 22 23 25 26
    1,355 pointsBadges:
    report
  • philpl1jb
    So far, we''ve wasted effort and time on this thread because you provide statements that are not clear. I don't understand what you're doing or want to do with indcators. Phil
    50,505 pointsBadges:
    report
  • 421
    thanks
    380 pointsBadges:
    report
  • 9783444184
    sorry all, actually i am tried another stuff that why i posted wrong question. i have got little bit solution from TomLiotta but some time program gives duplicate number..
    1,355 pointsBadges:
    report
  • TomLiotta
    but some time program gives duplicate number.. Earlier, you listed three rules. The first two rules were like this:
    • 1-user input digits can’t be duplicate...
    • 2-generated number can’t be duplicate...
    If you are writing about "duplicate" numbers now, you need to tell which of those two rules is being violated. Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Further, your third rule seemed to contradict that rules against duplication:
    • 3-input number and generated number if equal then successful. like (123456=123456)
    To me, that makes it seem as if your goal ("successful") is to generate a 'duplicate' number. That rule doesn't seem to fit with any of the rest of the whole thread. Tom
    125,585 pointsBadges:
    report
  • 9783444184
    hi Tom thanks, i want to generate 6 digits non repeating and duplicate number. do<6 123456 (if this is my generated no. ) next generated no. like as 987654 next 741235 next .........
    1,355 pointsBadges:
    report
  • philpl1jb
    It seems as if you should have the ability to do this with the code that has been provided. Phil
    50,505 pointsBadges:
    report
  • 9783444184
    [...] Need help creating a 6 digit non repeating random number for RPGLE AS400?  CharlieBrown, TomLiotta, Philpl1jb will have the answers for [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following