11/2/2005 4:04 PM  
Posts: 70 Rating: (13) 
Hi All I need to generate random numbers for some simulation software to add signal noise etc. I am hoping to find a function written already but so far no luck. SFC64 has been suggested but you would still need to feed this through some sort of pseudorandom algorithm that I'm trying to avoid writing ;) Any suggestions appreciated! 
11/3/2005 8:59 AM  
Joined: 8/31/2005 Last visit: 12/4/2018 Posts: 217 Rating: (40) 
Hi Reuben! Have a look at this little tool: http://support.automation.siemens.com/WW/view/en/8502062 It says: "ANSWER: You can use the system function SFC64 "TIME_TCK" to generate a random number. From the system time you create the absolute value and then run an integer division with the upper limit as divisor. Determine the remainder left by this division operation. You can use this number as random number." 
Greetings, Chris 

11/3/2005 3:45 PM  
Posts: 70 Rating: (13) 
Hi Chris thanks for the reply. I don't have a SIMATIC card to check the sample code in your link, but the description sounds like MOD'ing the tick count with the upper limit (divide by the upper limit and take the remainder == modulo operation). The tick count is simply an integer value in milliseconds, ie: it is increasing at a steady rate. Using this method might be OK every once in a while, but not on a continuous basis, ie: adding random noise every clock cycle, as the "random" value will follow an obvious trend. I'm thinking of taking the tick count and putting it through a series of XORs and ROTs based on the first few bits in the tick count (this is in millisecods so should change often). 
11/3/2005 5:09 PM  
Posts: 70 Rating: (13) 
Ok this is what I have used, maybe it can help someone else. I know the Randum Number Purists won't like it but it's fine for what I need right now: // Scramble the bits by rotating and XORing them // Convert to float // Sine produces a value within 1..1, so add 1 and multiply by 50 to scale from 0  100 
12/22/2005 4:54 AM  
Posts: 1 Rating: (0) 
I Needed a random number in an exclusive range ( 102000) on an S7200. This number was generated off of an operator input. I simply used an add block to add 1 to a register every scan when the number reached 2000 I wrapped back to 10. When the operator pressed the button I captured the current value. The scan of this PLC was ~3ms so I repeated ~ every 6seconds. I realize that the random part of this equation was when the operator pressed the button, but I found this method to be extremely useful for what I needed. I understand this might not help in your paticular case but if you had an input in your system that is completely random this may work for you. 
Follow us on