LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Choosing between Random and Control

Solved!
Go to solution

I have 2 questions.

 

1. I have a random number and a control. The value of my indicator should be equal to the value of my control, however, when the user pushes a boolean button,  a random number should be generated, the random number generator should always have preference over the control.

 

2. If I want to choose random number [2 4 6 7] of these 4 numbers only, what will be the best approach, since the random number generator outputs values in the range 0 to 1.but I want random numbers of only these four numbers,i.e 2 or 4 or 6 or 7

 

Thank you.

0 Kudos
Message 1 of 6
(3,291 Views)
  1. Use a case structure and place your random generator in one case and your control in the other case. Place the indicator outside th the right. Connect your boolean to the case selector.
  2. Create an array containing your four numbers as a diagram constant. create a random number, multiply by 4, round to -inf, and use it to index into your array.

See how far you get. 🙂

0 Kudos
Message 2 of 6
(3,288 Views)

Here's a quick example (LabVIEW 8.5)

 

 

(The control is in the other case, but you could easily als place it to the left of the case structure. Would make the code easier to read :))

 

Message Edited by altenbach on 10-30-2008 12:20 PM
Download All
Message 3 of 6
(3,274 Views)

Thank you Altenbach.

 

I run your VI , and it worked fine, but one issue is that when I changed to random, I want the random number to only generate once, until I pressed it again.  I had already completed my vi before I saw your second post.

 

I have posted the vi, the way I envisioned it to be , but like what you posted, when I click on the rand button, it keeps on inputing values, instead of just one value, until pressed again.

0 Kudos
Message 4 of 6
(3,256 Views)
Solution
Accepted by topic author ade77

ade77 wrote:

I have posted the vi, the way I envisioned it to be , but like what you posted, when I click on the rand button, it keeps on inputing values, instead of just one value, until pressed again.


Then use an event structure, for example. 🙂

 

0 Kudos
Message 5 of 6
(3,252 Views)
Thank you Altenbach.
0 Kudos
Message 6 of 6
(3,241 Views)