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
Old August 25th, 2006, 04: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
Old August 25th, 2006, 05:33 PM   #2
geniusintraining
Lifetime Supporting Member + Moderator
United States

geniusintraining is offline
 
geniusintraining's Avatar
 
Join Date: Jun 2005
Location: SC
Posts: 3,698
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 Save 5% on all cables and trainers, enter coupon code PLCTalk at check out
  Reply With Quote
Old August 25th, 2006, 05:51 PM   #3
TdB
Member
Italy

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

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, UMSA, United Marxist States of America
Posts: 5,758
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
Old August 26th, 2006, 02: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
Old August 26th, 2006, 04: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
Old August 26th, 2006, 06: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
Old August 26th, 2006, 10:09 AM   #8
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, UMSA, United Marxist States of America
Posts: 5,758
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
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
Usless but maybe fun excercise ndzied1 LIVE PLC Questions And Answers 6 May 15th, 2006 06:28 AM
PLC 5/04 random number generator seat14 LIVE PLC Questions And Answers 2 December 10th, 2005 11:29 PM
Random number Shahed LIVE PLC Questions And Answers 4 December 3rd, 2005 03:25 AM
S7 Random Number Generator RRobbins LIVE PLC Questions And Answers 10 November 18th, 2004 02:02 AM
Random number generator for PLC5 Contr_Conn LIVE PLC Questions And Answers 11 September 8th, 2004 01:57 AM


All times are GMT -5. The time now is 01:21 AM.


.