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...
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)
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
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.....
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
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
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
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
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.
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)
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
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
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
[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 ]
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.
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
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
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
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
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..
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
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 .........
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 36 Replies