Random number generator

chud

Member
Join Date
Oct 2007
Location
KALAHARI
Posts
1,121
Ive got a client that needs random numbers generated for a security system. Just want to know if any 1 has some ladder or ST software or scripts for random number generation. It doesnt have to be some crazy generator. Was thinking about doing it with time values, but then again that isnt very random.

Any help would be app.
 
Here is a really flash one.

http://forums.mrplc.com/index.php?download=161

And a bit of a description

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
The MOD operation is the integer
 
Thanks Bob.The problem we had was that we needed a list of random numbers between 0-100. The client then specifies on a Hmi what percentage of employes he wants to be stopped and searched inside a turnstile(This is South Africa so I would assume %100 all the time.....hehehe). What we came up with is taking a couple of arrays of fixed randomly generated numbers and according to the percentage chosen, only read so many registers. Say 20% we read 20 registers of a certain array(we obviously start from a different register every time the 0-100 table resets). Whilst we scan through a table of 0-100 we compare the registers read from the random array and the list of 0-100.After 100 we reset fixed list to zero.Every day we will use a different table of random numbers. Hope this makes sense and that it will work
 
Last edited:
Have one for that with settable limits. Uses the PLC scan flag which makes it more random. Limits can be set between 0-100, 276-895, etc etc. Anywhere you wish. Post if you want it. It uses random values as timer SV points so that each time a device turns on the time is different. The limits mean that the timers have random values within the limits.
 
How about something like this?

random_number_counters.jpeg
 
In this thread: http://www.plctalk.net/qanda/showthread.php?t=20146
I posted a random number generator for a turnstile application that uses the PLCs free running clock to create a random number. Combined with the fact that people also move at random speeds it will be impossible for a human to predict what number was selected for the next search.

For you applicaiton, each time a new random number is needed, the bitwise NOT of the free running clock is placed in the 32 bit math register, then a double divide by 100 is performed. The remainder is now in S:13 and is between zero and 99. The quotient is discarded. One is added to the remainder to make it one to one hundred. The next number will be impossible to predict, even to someone one who knows the PLC program.

The program shown was for an AB Micrologix but it can be adapted to any PLC.
 
Last edited:
I cannot find the latest version which is better but this does work of an 0.02 second clock pulse. The PLC scan is better as it is more random. It may give you a few ideas though. Hope it helps.
 
Here's an S7-300 implementation and some charts showing the frequency distribution for 3 different samples.

rancode001.JPG

1000ran.JPG



10000ran.JPG

100000ran.JPG
 
Last edited:
Thanks again for all the help you guys gave. This is the solution I came up with, would like to know what you guys think, and if I should make any alterations.
I tested the program about 10 times and comes to exactly the percentages that you want to be searched
Also dont know how to print program to pdf so i pasted the stx file
 
To print to pdf you require either full Acrobat or another pdf writer. There are plenty of free ones available - check at www.cnet.com or Google search. They do not have the full capabilities of Acrobat but are free. I use full Acrobat Professional for commenting, etc etc but it ain't cheap.
 

Similar Topics

Hey folks, I was just wondering what thoughts were about a completely 100% random number generator. I looked on The Google but didn't really open...
Replies
54
Views
16,436
Hello, Could somebody please help me out with coding a 'Random number generator' in vijeo citect. For example if i create an analog Local...
Replies
3
Views
3,726
Hi,Does anybody know if there are any routines in unity pro that produce random numbers like the routine rand() in C ?
Replies
1
Views
4,021
Can anyone help me create a few ladder logic lines to randomly generate intergers btw 0-100. I have tryed loading the scan timer value, then ANDD...
Replies
16
Views
13,278
Hi guys, I need your valuable suggestions about writing a module (AWL Step7) generating random integer numbers... Let's say the users define the...
Replies
19
Views
20,145
Back
Top Bottom