Help - Search - Members - Calendar
Full Version: Random Number Generator
Forums.MrPLC.com > PLCs and Supporting Devices > Allen Bradley
lotuseater
I am curious if anyone knows a good way to create a random number between 1 and 13 using Logix 5000.

I have seen the example on AB's website found here:
http://rockwellautomation.custhelp.com/cgi...171&p_olh=0

I think I may be able to use that example with some additional scaling. But, does anyone have any other options?
There is a specific instance I am wanting to use this for, if we need to get into additional details I will. thumbsupsmileyanim.gif

Thanks,
Jake
BobLfoot
How often do you need a number generated. There are several websites random.org for one which generate random sequences of numbers. A file of 1024 Dints would not take up much space in a CLGX 5000 and random.org could generate 1024 numbers 1 thru 13 in a random sequence. A pointer would give you the next number each time you need it.

You might also be able to use an EWEB module and hit a web site and get the number for each need.
Sleepy Wombat
I uploaded code for an Omron version in the Omron PLC code section based on the following

Generates a Pseudo random number using the mixed congrential method.
Formula r(i+1) = (a r + b) MOD N
This will generate a random number between 0 & N-1 with N = 2 (pwr 20) = 1,048,576, a = 1909, b = 221,571

You will see that at the end if you need to get a number between say 1-100 , or 1-1000 then simply multiply the result by the upper range.

http://forums.mrplc.com/index.php?autocom=downloads&showfile=161

manav
Never needed a random number generation in control, but it could be done with scan time bits, as the scan time in usecs keeps changing even for a static program running with no change of states. Even a periodic task takes different times for execution every scan. Since there is an inbuilt randomness in the scan times due to the hardware design, this would be the best inbuilt randomness that you can feed off to develop an algorithm for a rand generator. It depends on the characteristics and frequency of the random number you want to generate that would determine the applicability.

I have developed a PID loop simulation algorithm in RLL. I used the trig functions with system times to generate a randomly fuctuating PV (scaled appropriately). The system seconds, minutes, hours etc. they keep changing, it is impossible to predict the result of the trigonometric functions at the system second level, as the scan times of periodic tasks are not perfect, hence you get a randomly fluctuating value. Of course in my case the frequency was to the tune of 10 Hz or so. If you need a higher frequency then you can of course try using the scan time bits directly.
rpraveenkum
About random number it is detailed discussion in this topic

http://forums.mrplc.com/index.php?showtopic=10073
lotuseater
Thank You for the Replies.

I'll do some more thinking on this when I get some time and see what I can come up with.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.