PLC programming random outputs

Status
Not open for further replies.

lquadros

Member
Hello there,

I am looking to make a PLC program, to generate random outputs ( about 8 ) for a game. Is there a way a PLC can do it ? Any ideas are appreciated.
 
Hello there,

I am looking to make a PLC program, to generate random outputs ( about 8 ) for a game. Is there a way a PLC can do it ? Any ideas are appreciated.


Search for what is called a Pseudo-Random Number Generator (PRNG) algorithm. And also look for some control inputs whose timing will be unpredictable, if not random, that can be used to "seed" the PRNG. If nothing else, you can use the low order digits of the clock, captured when a button is pushed.

To implement a PRNG, you need a capable programming language (C, Java, Basic, Perl, etc.) , not just a special PLC relay control code language.
 
Search for what is called a Pseudo-Random Number Generator (PRNG) algorithm. And also look for some control inputs whose timing will be unpredictable, if not random, that can be used to "seed" the PRNG. If nothing else, you can use the low order digits of the clock, captured when a button is pushed.

To implement a PRNG, you need a capable programming language (C, Java, Basic, Perl, etc.) , not just a special PLC relay control code language.

virtually any modern PLC has the math functions to calculate a PSRNG.

we are talking simple algebra here, not rocket science.
 
Math function for Random outputs

Math function for Random outputs

petersonra,

Can you give me some more tips about this? I am using Omron CS1H-H CPU. Thanks for your input.
 
petersonra,

Can you give me some more tips about this? I am using Omron CS1H-H CPU. Thanks for your input.

I am afraid that my knowledge of Omron PLCs is very limited.

There are simple ways to get something that is random enough for most purposes.

what is it you are trying to do?
 
I am afraid that my knowledge of Omron PLCs is very limited.

There are simple ways to get something that is random enough for most purposes.

what is it you are trying to do?

These OMRON units seem to have a proprietary programming language which is optimized to implement ladder diagrams, and can only with difficulty do anything else. In particular it does not include a random number generator function.

You have bitten off a very large programming task.
 
Random output generation with PLC

Random output generation with PLC

petersonra

I am thinking of a game called whac -a - mole
 
petersonra

I am thinking of a game called whac -a - mole

I think a simple shift register that shifts a single bit once a scan would work.

it would be more or less random when a mole pops up.

take a n 8 bit register and successively shift a single bit from bit 0 thru 7 and than start back at 0.

when you need to select a mole just use whichever bit is on at the time. it will be adequately random for your purposes.
 
Hello there,

I am looking to make a PLC program, to generate random outputs ( about 8 ) for a game. Is there a way a PLC can do it ? Any ideas are appreciated.

Notice that even the 'function' that is available at higher than ladder programing languages alludes to PSEUDO Random Number Generator. Whenever a formula is used, and it is used repeatedly, it can no longer be random, just gives the appearence of randomness as most human brains can not detect the repetition. Just like in cryptography, there is a 'key'.
 
Notice that even the 'function' that is available at higher than ladder programing languages alludes to PSEUDO Random Number Generator. Whenever a formula is used, and it is used repeatedly, it can no longer be random, just gives the appearence of randomness as most human brains can not detect the repetition. Just like in cryptography, there is a 'key'.
The human brain is fairly easily fooled in fact. I once did a program for a "dancing waters" fountain feature where the user wanted a specific routine that played once per hour, but when running in between shows, they wanted a "randomized" set of changes in water flow and squirts and such. I set up a simple 10 step timer function that repeated itself every 5 cycles, people noticed. But once I changed it to 7 cycles, they perceived that to be random... :angel:
 
I'm not sure how inexpensive the Omron PLCs are, but if you are not locked into using that brand, you may want to look into an IDEC. They are also low cost, and I am pretty sure they have a random number function. I haven't programmed one in a long time, but they had a pretty easy-to-learn program compiler. I wrote some extremely complex algorithms that made my IDEC's do things that even their own design engineers didn't know they could do.

Aside from that, the suggestion of using the lower digits of the clock is probably going to be your best bet. The randomness would come in via the random delay caused by human interaction.

That sounds like a really fun project to do. Good luck with it. :thumbsup:
 
Aside from that, the suggestion of using the lower digits of the clock is probably going to be your best bet. The randomness would come in via the random delay caused by human interaction.

For example, each "whack" event would cause a timer capture that could then be used to randomize the next one or several mole events.
Just make sure that the timing of the timer capture is not controlled entirely by the program's internal timing.
(Although even that may be unpredictable enough to meet Jraef's criterion.)
 
Status
Not open for further replies.
Top