Posted 24 May 2016 Hi, I need to create an Array Filled with random bool values to a certain Purcentage... ex : 25% of True... would look somewhat like this..... 001011101011000010101011010100101010101... not like 111111111111111100000000000000000 or 00010001000100010001 I will be using a value introduced by the user as an Int from the HMI then create the Array with this random function... Please Help... I am losing patience over this !! Thanks Share this post Link to post Share on other sites
Posted 24 May 2016 Never heard of such a function in any PLC I've worked on in 18 years. Share this post Link to post Share on other sites
Posted 24 May 2016 The functions in the PLC are the same no matter if you write them ladder or ST. It's the same exact command set. Share this post Link to post Share on other sites
Posted 24 May 2016 PLC got no random generator function as far as I know (something like the RAND function in excel). It should be possible using ST but you need to write your own code Random Generator code to create the random 0 and 1, then use another script to check the consistency with the percentage you've inputted, and recursively execute the script again. One site you might interested to check out for the actual Random Generator algorithm :https://cdsmith.wordpress.com/2011/10/10/build-your-own-simple-random-numbers/ PLC of course have the MOD function in ST, and regarding the seed you can use PLC clock seconds. But I'm sure it'll be a tiresome job :D Share this post Link to post Share on other sites
Posted 25 May 2016 Just one tip: Sysmac Controllers already have RAND FB to generate pseudo-random numbers. Once you have th random number, should not be difficult for you to generate small FB to populate with 1 and 0 your array Share this post Link to post Share on other sites