![]() ![]() ![]() ![]() ![]() ![]() |
||
![]() |
||
![]() ![]() ![]() ![]() This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
![]()
|
New Here? Please read this important info!!!
![]() |
#1 |
Member
![]() ![]() Join Date: Aug 2006
Location: Maranello
Posts: 5
|
![]()
Hi guys,
I need your valuable suggestions about writing a module (AWL Step7) generating random integer numbers... Let's say the users define the range of the numbers and an input (on negative edge) triggers the result... I did one myself but it's still not true random... Any ideas ?? Andy |
![]() |
![]() |
#2 |
Lifetime Supporting Member + Moderator
|
Try searching...
it has been covered many times, I got 40 hits...there are several that deal with S7, this one looks good http://www.plctalk.net/qanda/showthread.php?t=11354 looks like the majority use a system clock to generate the numbers
__________________
www.PLCCable.com PLC Communication Cables, PLC Trainers, Fluke Meters, MicroLogix, ControlLogix, Siemens, Allen Bradley and more... all your automation needs... ((NEW)) After Market 1784-U2DHP Allen Bradley USB to DH+ and Gateways |
![]() |
![]() |
#3 |
Member
![]() ![]() Join Date: Aug 2006
Location: Maranello
Posts: 5
|
Thanks a lot
![]() Andy |
![]() |
![]() |
#4 |
Member
|
Some assembly required
Google "Parks Miller Randon Number". This will be easy to implement on a S7.
Code:
int intrnd (int& seed) // 1<=seed<=m { #if LONG_MAX > (16807*2147483647) int const a = 16807; //ie 7**5 int const m = 2147483647; //ie 2**31-1 seed = (long(seed * a))%m; return seed; #else double const a = 16807; //ie 7**5 double const m = 2147483647; //ie 2**31-1 double temp = seed * a; seed = (int) (temp - m * floor ( temp / m )); return seed; #endif } |
![]() |
![]() |
#5 |
Member
|
What do you need the random number generator for ?
|
![]() |
![]() |
#6 |
Lifetime Supporting Member
|
Peter, this has been discussed numerous times on this site, are you NOW saying a plc can generate random numbers?
NONE of y'all give me the brand thing.
__________________
http://www.patchn.com Industrial Electrical & Maintenance @ www.patchn.com "Tell me and I forget, show me and I remember, involve me and I understand." |
![]() |
![]() |
#7 | |
Member
![]() ![]() Join Date: Aug 2006
Location: Maranello
Posts: 5
|
Quote:
but i'm still curious to know one proper random function (pseudo looking of course) Tnx for your tips ![]() Andy |
|
![]() |
![]() |
#8 | ||
Member
|
There are no true random number generators
This algorithm is one in numerical recipes in C and it is really a pseudo random number generator PRNG. It should be obvious that that same seed will generate the same sequence of pseodu random numbers.
Quote:
Quote:
|
||
![]() |
![]() |
#9 |
Member
![]() ![]() Join Date: Jul 2019
Location: Den Bosch
Posts: 2
|
just take values from actual time like ((milliseconds*(minutes+5)/(hrs+3)+17)*3) and convert to a byte, then you have a pretty random number between 0 and 255...
:-) |
![]() |
![]() |
#10 |
Member
|
You know this post is 13 years old, right?
__________________
Go Hawks!!! ![]() |
![]() |
![]() |
#11 |
Member
![]() ![]() Join Date: Jul 2019
Location: Den Bosch
Posts: 2
|
sorry didn't realize, but I myself was looking for a random generator to found out my plc couldn't, so I made something else, but while searching I came to this site and thought I'd share .... :-(
|
![]() |
![]() |
#12 |
Member
|
Random numbers have changed since then
__________________
Whatever hits the fan will not be evenly distributed. |
![]() |
![]() |
#13 |
Member
![]() ![]() Join Date: May 2010
Location: London
Posts: 540
|
Because of Brexit...?
__________________
I promise to get it right 3rd time every time. |
![]() |
![]() |
#14 |
Lifetime Supporting Member + Moderator
|
__________________
www.PLCCable.com PLC Communication Cables, PLC Trainers, Fluke Meters, MicroLogix, ControlLogix, Siemens, Allen Bradley and more... all your automation needs... ((NEW)) After Market 1784-U2DHP Allen Bradley USB to DH+ and Gateways |
![]() |
![]() |
#15 |
Member
|
Any way of the forum auto-locking a thread after x years? Or months?
__________________
Never underestimate the quality of idiots that will be running your machines ![]() http://aabeck.com |
![]() |
![]() |
Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
S7 Random Number Generator | RRobbins | LIVE PLC Questions And Answers | 14 | July 8th, 2016 08:36 AM |
Usless but maybe fun excercise | ndzied1 | LIVE PLC Questions And Answers | 6 | May 15th, 2006 07:28 AM |
PLC 5/04 random number generator | seat14 | LIVE PLC Questions And Answers | 2 | December 11th, 2005 12:29 AM |
Random number | Shahed | LIVE PLC Questions And Answers | 4 | December 3rd, 2005 04:25 AM |
Random number generator for PLC5 | Contr_Conn | LIVE PLC Questions And Answers | 11 | September 8th, 2004 02:57 AM |