Lean MES Open Source Manufacturing Execution System
Flexible Manufacturing Solutions through Open Standards and Free Software....
RSLogix 5000 (19.01) (PLC) Random Number Generator.


The following random generator is adaptation for RSLogix5K
of C# code: http://www.codeproject.com/KB/recipes/SimpleRNG.aspx (byJohn D. Cook).

Workaround for signed 32-bit integers DINT, C# code uses unsigned 32-bit integers.
The precision of REAL data-types is reduced.
Is Importable/Exportable Routine.Called by JSR from Continous Main Task.
Generates random values between ]0; 1[, takes 32 scans to generate a random value.
It seeds itself, although option with controller's clock is possible. Has not been statistically tested.

Copyright (C) 2011 Peter Tiagunov peter.tiagunov@leanmes.net

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.

Downloads:

Source code here: RandomGen.L5X.zip

Ladder Logic report: Random_Number_Generator_RSLogix_5000.pdf

Watch in action: RSLogix5000_Random_Number_Generator.mp4


Statistics:

select top 32 [time],[value] from PIDA.piarchive..picomp
where [tag] like 'Application:RSLinx Enterprise:CPU1.Program:MainProgram.f_Random'
and [time] between '2011-12-27 16:00:00.000' and getdate()
--and [timestep]=@v_timestep
order by [time] desc

time                    value
----------------------- ----------------------
2011-12-27 16:57:28.817 0.8134614
2011-12-27 16:57:27.190 0.2160121
2011-12-27 16:57:25.567 0.640706
2011-12-27 16:57:23.830 0.5210752
2011-12-27 16:57:22.207 0.3455091
2011-12-27 16:57:20.580 0.6930602
2011-12-27 16:57:18.957 0.4613169
2011-12-27 16:57:17.330 0.5821513
2011-12-27 16:57:15.690 0.7602278
2011-12-27 16:57:13.970 0.057063
2011-12-27 16:57:12.347 0.349991
2011-12-27 16:57:10.720 0.255106
2011-12-27 16:57:09.097 0.563403
2011-12-27 16:57:07.470 0.5470275
2011-12-27 16:57:05.737 0.318302
2011-12-27 16:57:04.110 0.9353553
2011-12-27 16:57:02.487 0.0993824
2011-12-27 16:57:00.860 0.4907291
2011-12-27 16:56:59.237 0.4542791
2011-12-27 16:56:57.500 0.9757954
2011-12-27 16:56:55.877 0.7693856
2011-12-27 16:56:54.237 0.3471405
2011-12-27 16:56:52.610 0.1454094
2011-12-27 16:56:50.970 0.6201302
2011-12-27 16:56:49.347 0.0579111
2011-12-27 16:56:47.720 0.4284925
2011-12-27 16:56:46.097 0.0512566
2011-12-27 16:56:44.470 0.7818134
2011-12-27 16:56:42.737 0.4439922
2011-12-27 16:56:41.110 0.385749
2011-12-27 16:56:39.487 0.953855
2011-12-27 16:56:37.843 0.5043723

(32 row(s) affected)


select
 a.value [Average]
,b.value [Mean]
,c.value [StdDev]
,d.value [Min]
,e.value [Max]
from
 PIDA.piarchive..piavg as a
,PIDA.piarchive..pimean as b
,PIDA.piarchive..pistd as c
,PIDA.piarchive..pimin as d
,PIDA.piarchive..pimax as e
where a.tag = b.tag and b.tag = c.tag  and c.tag = d.tag and d.tag = e.tag
and a.time = b.time and b.time = c.time and c.time = d.time and d.time = e.time
and a.tag ='Application:RSLinx Enterprise:CPU1.Program:MainProgram.f_Random'
and a.time between '2011-12-27 16:00:00.000' and getdate()

Average             Mean                StdDev              Min                  Max
------------------- ------------------- ------------------- -------------------- -----------------
0.496422213454471   0.495557625116912   0.236309935283415   0.000133663648739457 0.999659717082977

(1 row(s) affected)


select count(*) as [Nr. of Samples] from PIDA.piarchive..picomp
where [tag] like 'Application:RSLinx Enterprise:CPU1.Program:MainProgram.f_Random'
and [time] between '2011-12-27 16:00:00.000' and getdate()

Nr. of Samples
--------------
2207

(1 row(s) affected)