PLCS.net - Interactive Q & A

PLCS.net - Interactive Q & A (http://www.plctalk.net/qanda/index.php)
-   LIVE PLC Questions And Answers (http://www.plctalk.net/qanda/forumdisplay.php?f=2)
-   -   Random number generator (http://www.plctalk.net/qanda/showthread.php?t=24963)

TdB August 25th, 2006 04:43 PM

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

geniusintraining August 25th, 2006 05:33 PM

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

TdB August 25th, 2006 05:51 PM

Thanks a lot :nodi:
Andy

Peter Nachtwey August 25th, 2006 05:53 PM

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
}


SimonGoldsworthy August 26th, 2006 02:18 AM

What do you need the random number generator for ?

rsdoran August 26th, 2006 04:23 AM

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.

TdB August 26th, 2006 06:49 AM

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 :beerchug:

Andy

Peter Nachtwey August 26th, 2006 10:09 AM

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?

xyntec August 11th, 2019 10:07 AM

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

:-)

Firejo August 12th, 2019 09:14 AM

You know this post is 13 years old, right?

xyntec August 12th, 2019 09:25 AM

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

paraffin power August 12th, 2019 03:28 PM

Quote:

Originally Posted by Firejo (Post 823560)
You know this post is 13 years old, right?

Random numbers have changed since then

Ronnie Sullivan August 13th, 2019 01:32 AM

Quote:

Originally Posted by paraffin power (Post 823602)
Random numbers have changed since then

Because of Brexit...?

geniusintraining August 13th, 2019 06:16 AM

Quote:

Originally Posted by Ronnie Sullivan (Post 823628)
Because of Brexit...?

No, I think lack thereof ;)

Aabeck August 13th, 2019 01:12 PM

Quote:

Originally Posted by Firejo (Post 823560)
You know this post is 13 years old, right?

Any way of the forum auto-locking a thread after x years? Or months?


All times are GMT -5. The time now is 05:45 AM.

.