Jump to content

Recommended Posts

Posted

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?

Thanks in advance!!! wink.gif

  • 1 year later...
  • MVP 2023
Posted

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.

  • Upvote 1
  • 1 year later...
Posted

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.

  • 8 years later...
Posted

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?

  • MVP 2023
Posted
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

  • MVP 2023
Posted
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.

Posted

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.

Knipsel.PNG

  • MVP 2023
Posted

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

image.thumb.png.abb4c05b5b9e52da08aeae7dbf4885a7.png

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.

  • MVP 2023
Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.