Random Service Pgm

This commit is contained in:
SJLennon
2024-01-28 15:13:17 -05:00
parent 523c327a36
commit 3525615191
4 changed files with 79 additions and 7 deletions
+7
View File
@@ -0,0 +1,7 @@
**free
//=== Prototypes for SRV_RANDOM routines =======================
dcl-pr Rand_Int int(10);
p_Low int(10) value; // lowest value of range
p_High int(10) value; // highest value of range
end-pr;
//=== End of SRV_RANDOM prototypes =============================
+13 -7
View File
@@ -2,7 +2,7 @@
Utility Service Programs.
* SRV_MSG
## SRV_MSG
Contains procedures to send messages from an RPG program.
@@ -16,13 +16,21 @@ Utility Service Programs.
**JobLogMsg**: Send provided text to the job log using Qp0zLprintf, a C function. For testing, a convenient alternative to the DSPLY opcode for longer messages.
* SRV_STR
## SRV_RANDON
Convenience procedures relating to pseudo random number generation.
**Rand_Int**
Return a random integer with a specified range.
## SRV_STR
Contains procedures to manipulate strings in an RPG program.
**CenterStr**: Center a string.
* SRV_SQL
## SRV_SQL
Helper procedures for RPG programs using embedded SQL.
@@ -52,11 +60,9 @@ Utility Service Programs.
RPG program to test the procedures in SRV_STR.
* SHOW
## SHOW
RPG program to display a 5250 message using the QUILNGTX API. Useful for testing, but possibly
JobLogMsg in SRV_MSG is more useful. Really should be part of SRV_MSG, but it is totally *FREE for and I have left SRV_MSG partially fixed.
SHOW_T
RPG program to test & exercise SHOW.
**SHOW_T**: RPG program to test & exercise SHOW.
+33
View File
@@ -0,0 +1,33 @@
**free
//==============================================================
//=== SRV_RANDOM service program contains convenience prodcedures
// for generating pseudo random numbers.
//==============================================================
ctl-opt nomain option(*nodebugio: *srcstmt);
// ------------------------------------------------------------
// RAND_INT - function to returns a pseudo randon integer
// such that the value is >= p_Low and <= p_High.
// ------------------------------------------------------------
// No validity checking on the parameters.
// Testing shows that a fairly even distribution is
// produced, but p_High is much less frequently returned.
// The underlying SQL function returns a number that is
// >= .0 and <= .1, but it rarely returns .1.
// CRTSRVPGM SRVPGM(LENNONS1/SRV_RAND) MODULE(Rand_Int) EXPORT(*ALL)
dcl-proc Rand_Int export;
dcl-pi Rand_Int int(10);
p_Low int(10) value;
p_High int(10) value;
end-pi;
dcl-s rf float(8);
dcl-s wk int(10);
exec sql set :rf = random();
wk = %int( (rf *(p_High - p_Low) + p_Low) );
return wk;
end-proc;
+26
View File
@@ -0,0 +1,26 @@
**free
// Test Rand_Int procedure by generating many randon integers and
// writing them to file RNUM.
ctl-opt DftActGrp(*NO) ActGrp(*CALLER) option(*nodebugio: *srcstmt)
BndDir('UTIL_BND');
/COPY copy_mbrs,srv_rand_p
exec sql set option datfmt=*iso,
commit=*none,
closqlcsr=*endmod;
dcl-s min int(10) inz(3);
dcl-s max int(10) inz(14);
dcl-s wk int(10);
dcl-s j int(10);
exec sql drop table lennons1.rnum;
exec sql create or replace table lennons1.rnum (num integer);
for j = 1 to 100000;
wk = Rand_Int(min:max);
exec sql insert into lennons1.rnum values :wk;
endfor;
*inlr = *on;
return;