Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Random numbers

Random numbers


Can any of you clever chaps give me(lazy I know!) structured text code that will generate a pseudo random number between 1 and 10?


RE: Random numbers

If you do not need the random number often, use the seconds lower digit of a real-time clock.

RE: Random numbers

Thanks for your replies,

I'll try and get the ladder version to work.

RE: Random numbers

I love ST programming, what processor are you using, I'll give it a shot.

RE: Random numbers

By the way, what may be a real life PLC application that requires a random number generation?

RE: Random numbers

The generation of random numbers for timers. I use them regularly to insert different values into timers for swimming pool water features. Sometimes the randomly generated timer values represent 2 decimal places. Sometimes minutes. Depends on the water features at hand.

RE: Random numbers

Thanks everyone,

These random numbers will be used for timer values. Its for a security lighting project I'm working on.

The PLC is a WAGO 750-841 and the software I'm using is CoDeSys.

Happy New Year.

RE: Random numbers

Nick, did you leave a request here for a simpler version of a number generator? If so, leave it again and I will see if I can post it somewhere for you to pick up.

RE: Random numbers

OldPfart, yes I did request your simpler version.

RE: Random numbers

Nick, I have not forgotten you. Just had one end up and the other end down (inverted). Not a pretty sight.

Will see if I can set something up for you tomorrow.


RE: Random numbers

Nick, still got head down and a*** up. Have not forgotten you.

Pleas be patient for another day or two.

RE: Random numbers


Still looking for help with random numbers?  In MATLAB, use the command rand.  I beleive C/C++ also have the function rand().

RE: Random numbers

As I was reading the replies...someone asked....what would you use it for...and bingo...olphart said for water feature timers.  Whoa...scary...that is EXACTLY what I used it for as well.  Did a control system for a water park feature that would do a random time for the events to occur.

fun project....

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


eBook: Product Innovation Platform Assessment
Over the past few years, there has been growing interest among industrial companies and solutions providers with regards to Product Innovation Platforms, where design, manufacturing and IoT tools are bundled into a single software package. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close