Random number generator

TdB

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
 
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
}
 
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.
 
SimonGoldsworthy said:
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
 
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.

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.

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?
 
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...

:)
 
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 .... :-(
 

Similar Topics

Hey folks, I was just wondering what thoughts were about a completely 100% random number generator. I looked on The Google but didn't really open...
Replies
54
Views
16,436
Hello, Could somebody please help me out with coding a 'Random number generator' in vijeo citect. For example if i create an analog Local...
Replies
3
Views
3,726
Hi,Does anybody know if there are any routines in unity pro that produce random numbers like the routine rand() in C ?
Replies
1
Views
4,021
Ive got a client that needs random numbers generated for a security system. Just want to know if any 1 has some ladder or ST software or scripts...
Replies
11
Views
8,805
Can anyone help me create a few ladder logic lines to randomly generate intergers btw 0-100. I have tryed loading the scan timer value, then ANDD...
Replies
16
Views
13,278
Back
Top Bottom