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.
-
Then you don't want random numbers at all. Random numbers don't follow rules like *I don't want 500 then 0 then 399 then 1` or *I don't want duplicates* because random numbers are random, and a valid sequence could very well be `500, 0, 399, 1, 0, 500`. – Ken White Dec 09 '20 at 19:30
-
2@KenWhite I think you missed something. There is nothing wrong with this question other than it being a little trivial – Design.Garden Dec 09 '20 at 20:32
2 Answers
Just plug the first random number back into the "Random Number (Range)" built-in VI.
Bonus Use a shift register to find a new random number within range of the last random number:

- 3,607
- 25
- 21
-
Be aware of the situation when 1st random number will be 499, and then next random numbers could be bigger than 500 :) The same belongs to the lower limit. – kosist Dec 10 '20 at 08:20
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).

- 2,868
- 2
- 17
- 30