Is there a way to generate random numbers between 0 and 500, but if first number is 300 not to deviate more than 20 for the next?

Viewed 669

Is there a way to generate random numbers between 0 and 500, but if first number for example, is 300, not to deviate more than 20 for the next? I don't want 500 then 0 then 399 then 1. Thanks.

2 Answers

Just plug the first random number back into the "Random Number (Range)" built-in VI.

enter image description here

enter image description here

Bonus Use a shift register to find a new random number within range of the last random number:

enter image description here

Previous answer refers to usage of minimal LabVIEW version 2019.

OpenG Numeric Library has similar function for generation of random number is the specified range, and supports earlier versions of LabVIEW.

Also, based on task description - if I've understood correctly - anyway random numbers should be in range 0 - 500; so we need to do additional check whether +/- 20 offset would not cause number "overflow".

Let me attach snippet of the solution which implements it. Note, that Select functions I've used just in order to show all the code on one snippet (instead of having Case Structure with pages).

Random number generation snippet

Front panel

Related