From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I randomly assign addition or subtraction in a for loop?

Solved!
Go to solution

Does anyone have any ideas for how I can randomly assign a for loop to add or subtract random numbers throughout various itterations?  My current code generates two random numbers and adds them together for a set number of itterations.  I need some random itterations to be subtraction.  Thanks in advance!  

0 Kudos
Message 1 of 3
(2,988 Views)
Solution
Accepted by topic author mcg123

Add another Random Number generator and compare the result against 0.5. Use a case structure around your addition/subtraction operator.

 

Seems like you might also want to output which operation actually got picked.

0 Kudos
Message 2 of 3
(2,975 Views)

Works great! Thank you.

0 Kudos
Message 3 of 3
(2,955 Views)