# Randoms Numbers

## Recommended Posts

Hi!

I need to generate a random number between 1 and 10.

I tried to generate the random number with a formula, but it always generates the same form or sequence (not random). Any ideas?

##### Share on other sites

Hi Wendy,

The type of random number generator depends on the application

I can offer you two different random number generators which you might find useful.

Random Number Generator 2.vlp

V570_Random_number_generator.vlp

##### Share on other sites

• 1 year later...
• MVP 2022

I don't know if Stein Yair is still around and participating in this forum, but I just want to say thanks. I had an urgent need for some random number generation and the above post is exactly what I needed.

By the way, Unitronics should consider adding a RND function to the available math functions in VisiLogic.

##### Share on other sites

• 1 year later...

Can pls somebody expain how the above two RNGs work or how can I open vlp files. I use jazz / M-90. THX!

##### Share on other sites

• MVP 2022

Install VisiLogic to open .vlp files.

##### Share on other sites

Hello kamrca,

You must use our software VisiLogic to open .vlp files.  The Jazz/M90 controllers will be programmed in U90, .U90 file extension.

Here is a basic overview of the programs:

The V570_Random_Number_Generator takes a 32-bit value and multiplies it by 75 (a random number) then divides that value by 65537, and the random number will be the remainder of the division.

The Random Number Generator 2 takes a 2.5msec count (generated by the system) and multiplies it by the current second (also a system operand).  Then it reduces the number such that it is a value between 1 and 10 by taking the remainder of the product created before and using the remainder after dividing by 10.

Hope this helps.

##### Share on other sites

Thx a lot to your kind answers!. I thout it was that

##### Share on other sites

• 8 years later...

I'am using the random number generator 2. I need random numbers between 0-5, I cant get the number 0. Can anyone give me the solution?

##### Share on other sites

Just generate 1 to 5 and then use (n-1).

##### Share on other sites

English:    Ok, thank you for your answer I will use it that way. Im an beginner with visilogic so i don't know how I can transform the random number into an MB. Can you help me with this?

Dutch:     Oke bedankt voor je reactie, Ik ga het op die manier gebruiken. Ik ben een beginner op het gebied van visilogic, dus weet nog niet hoe ik het random number kan converteren naar een memory bit. Kan je me hiermee helpen?

##### Share on other sites

• MVP 2022
10 hours ago, guusminnaard said:

beginner with visilogic so i don't know how I can transform the random number into an MB

Guus, your question implies that you are indeed  a beginner in Visilogic.  The forum is not really here to help you learn basics....it's up to you to go through a big initial learning curve.

You need to thoroughly read through the help files available in Visilogic, and learn what the various working operands all do, and how they work.

You then need to experiment with basic ladder structures using an actual plc for trial and error learning.   Then you can start on building programs you need, and any major stumbles along the way the forum can help.

cheers, Aus

##### Share on other sites

• MVP 2022
12 hours ago, guusminnaard said:

i don't know how I can transform the random number into an MB

This has no meaning. An MB is a bit - it is binary, either 0 or 1. A random number would be an integer, typically an MI.

##### Share on other sites

ok, thanks for the reactions. I my program like this now. I need to use the random number to switch an random target, my question is how do i use my random number to switch an output/target? I tried some things but I'm not expierenced enough to know why is doesn't work. So maybe you guys have an idea.

This project is for an  shooting range, so the random number need to switch an random target.

##### Share on other sites

• MVP 2022

Here is how I would do the part you are uncertain of:

You don't have to use vector functions - you can just use a series of compares - but this is easy and concise. You also don't have to group the elements in rung 3 the way I did with SB 1. I just like to group similar items in that way to save space and make for easier readability.

##### Share on other sites

Wow! Thank you Flex, for this example!

##### Share on other sites

• MVP 2022

I probably should have put in rung comments:

Rung 1 - reset all 6 MBs

Rung 2 - Store 1 in the bit corresponding to the offset value of the random number MI

Rung 3 - turn on the correct output

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×