LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

generate random number between -10 and 110

Solved!
Go to solution

Hello, Im trying to generate a random number between -10 and 110.  This is what i have so far. I'm still new to labview so i don't really know what to do. Any help would be great!!!

 

Screen Shot 2017-04-09 at 17.54.27.png

0 Kudos
Message 1 of 5
(9,497 Views)

Hello, Im trying to generate a random number between -10 and 110.  This is what i have so far. I'm still new to labview so i don't really know what to do. Any help would be great!!!

 

Screen Shot 2017-04-09 at 17.54.27.png

0 Kudos
Message 2 of 5
(9,493 Views)

You need a number between -10 and 110, that is a range of 120 not 100, and you will also need to offset that by -10 otherwise you will get values between 0  and 120.

 

You only need to change one constant and add a subtraction to you vi to complete it. You can also remove the coerce, if you set up properly it should never be outside of range.

 

[EDIT] Variables != Constant.

0 Kudos
Message 3 of 5
(9,495 Views)
Solution
Accepted by topic author Kmfood123

Let's take a look at what your VI currently does.

 

It starts by finding a random number between 0.000 and 1.000.  It multiplies that result by 100.  At this point, you have a number between 0.000 and 100.000.  You check to see if this value is in the range of -10 to 110.  It always is so the value is output along with a true.

 

After a second completes, the loop reads the true and stops to output both the true as well as the value between 0 and 100.

 

There's quite a few things strange with this.

1) It will always be in range.  The check doesn't provide any value.

2) In order for the loop to stop, it'll always output a true constant.  This doesn't provide you any benefit.  If it's always going to be true, just use a true constant elsewhere to make your code more readable and remove the need to output the value.  If it's not used elsewhere, delete the wire so you're not creating needless tunnels.

3) What's the purpose of the loop?  Do you want a new value every second?  If so, you'll want to move the indicator inside the loop and use something else (user interaction?) to stop the loop.

4) The algorithm itself has nothing to do with LV.  But, it's off.

 

As was mentioned, you need to generate a range of 120.  Start by multiplying by 120.  That gives you a range of 0.000-120.000.  That's not quite what you want.  But, if you subtract 10 from that you'll get a range of -10.000-110.000.  That's what you're after isn't it?  Once you have that, you can delete the rest of the code in your while loop.  It doesn't do anything.

0 Kudos
Message 4 of 5
(9,465 Views)

Thank you so much!!! I really appreciate you showing what was wrong with my initial program, and your program worked very well. Thank You!!!!

0 Kudos
Message 5 of 5
(9,448 Views)