You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
Thread Tools Display Modes
Unread August 25th, 2006, 05:43 PM   #1
TdB
Member
Italy

TdB is offline
 
Join Date: Aug 2006
Location: Maranello
Posts: 5
Smile Random number generator

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
  Reply With Quote
Unread August 25th, 2006, 06:33 PM   #2
geniusintraining
Lifetime Supporting Member + Moderator
United States

geniusintraining is online now
 
geniusintraining's Avatar
 
Join Date: Jun 2005
Location: SC
Posts: 6,600
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
  Reply With Quote
Unread August 25th, 2006, 06:51 PM   #3
TdB
Member
Italy

TdB is offline
 
Join Date: Aug 2006
Location: Maranello
Posts: 5
Thanks a lot
Andy
  Reply With Quote
Unread August 25th, 2006, 06:53 PM   #4
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,987
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
}
  Reply With Quote
Unread August 26th, 2006, 03:18 AM   #5
SimonGoldsworthy
Member
United Kingdom

SimonGoldsworthy is offline
 
SimonGoldsworthy's Avatar
 
Join Date: Mar 2005
Location: England
Posts: 1,079
What do you need the random number generator for ?
  Reply With Quote
Unread August 26th, 2006, 05:23 AM   #6
rsdoran
Lifetime Supporting Member
United States

rsdoran is offline
 
rsdoran's Avatar
 
Join Date: Apr 2002
Location: Birmingham, AL
Posts: 7,372
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."
  Reply With Quote
Unread August 26th, 2006, 07:49 AM   #7
TdB
Member
Italy

TdB is offline
 
Join Date: Aug 2006
Location: Maranello
Posts: 5
Quote:
Originally Posted by SimonGoldsworthy
What do you need the random number generator for ?
I needed it for some program testing months ago... so i did one which could do the job...
but i'm still curious to know one proper random function (pseudo looking of course)
Tnx for your tips

Andy
  Reply With Quote
Unread August 26th, 2006, 11:09 AM   #8
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,987
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:
Peter, this has been discussed numerous times on this site, are you NOW saying a plc can generate random numbers?
Yes, at least pseudo random numbers. The algorithm was always there for anybody to find. There are many others but this is one that is recognized as being a good considering the effort it takes to make it go. Go to www.nr.com and order the book.

Quote:
NONE of y'all give me the brand thing. Today 12:18 AM
I will, why not? Those PLCs that don't support 32 bit INTs or DINTs can't do this. Actually at 32x32 bit multiply and 32 bit divide can be done on a SLC but it would be extremely messy. A S7 can do this easily and efficiently. So?
  Reply With Quote
Unread August 11th, 2019, 11:07 AM   #9
xyntec
Member
Netherlands

xyntec is offline
 
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...

:-)
  Reply With Quote
Unread August 12th, 2019, 10:14 AM   #10
Firejo
Member
United States

Firejo is offline
 
Firejo's Avatar
 
Join Date: Jun 2008
Location: Redmond, WA
Posts: 1,307
You know this post is 13 years old, right?
__________________
Go Hawks!!!
  Reply With Quote
Unread August 12th, 2019, 10:25 AM   #11
xyntec
Member
Netherlands

xyntec is offline
 
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 .... :-(
  Reply With Quote
Unread August 12th, 2019, 04:28 PM   #12
paraffin power
Member
England

paraffin power is offline
 
paraffin power's Avatar
 
Join Date: Aug 2002
Location: Manchester
Posts: 495
Quote:
Originally Posted by Firejo View Post
You know this post is 13 years old, right?
Random numbers have changed since then
__________________
Whatever hits the fan will not be evenly distributed.
  Reply With Quote
Unread August 13th, 2019, 02:32 AM   #13
Ronnie Sullivan
Member
United Kingdom

Ronnie Sullivan is offline
 
Join Date: May 2010
Location: London
Posts: 540
Quote:
Originally Posted by paraffin power View Post
Random numbers have changed since then
Because of Brexit...?
__________________
I promise to get it right 3rd time every time.
  Reply With Quote
Unread August 13th, 2019, 07:16 AM   #14
geniusintraining
Lifetime Supporting Member + Moderator
United States

geniusintraining is online now
 
geniusintraining's Avatar
 
Join Date: Jun 2005
Location: SC
Posts: 6,600
Quote:
Originally Posted by Ronnie Sullivan View Post
Because of Brexit...?
No, I think lack thereof
__________________
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
  Reply With Quote
Unread August 13th, 2019, 02:12 PM   #15
Aabeck
Member
United States

Aabeck is offline
 
Aabeck's Avatar
 
Join Date: Feb 2013
Location: Detroit
Posts: 1,515
Quote:
Originally Posted by Firejo View Post
You know this post is 13 years old, right?
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
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
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


All times are GMT -5. The time now is 10:32 AM.


.