04-09-2017 05:02 PM
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!!!
Solved! Go to Solution.
04-09-2017 05:06 PM
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!!!
04-09-2017 05:07 PM - edited 04-09-2017 05:07 PM
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.
04-09-2017 05:36 PM
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.
04-09-2017 06:38 PM
Thank you so much!!! I really appreciate you showing what was wrong with my initial program, and your program worked very well. Thank You!!!!