LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in Uniform Random .vi

Try feeding xmin = xmax to the Uniform Random.vi random number generator.

You'll get an array of NaN, while you would expect a constant array of value xmin.

 

 

Screen Shot 2014-09-25 at 10.48.57.png

 

 

Error -20069 returned by the VI has the following description in "Explain Error..."

 

Analysis: The number of samples must be greater than or equal to four.

(my emphasis)

 

 

Tested in LV 2013 SP1 W7 64bits

0 Kudos
Message 1 of 11
(3,286 Views)

Makes sense to me.  It probably creates an array of random numbers which is must then scale over your X range.  Since your X-range is zero (1 to 1), you are probably getting a divide by zero error thus giving the NaN.

 

I agree with you that it seems like all the results should be 1.  But this is such a corner case of this function, I don't see any real world case where you'd use it like this.

0 Kudos
Message 2 of 11
(3,283 Views)

I did use a corner case. I did not know that they were not recommended in LV...

Message 3 of 11
(3,277 Views)

No.  A corner case means someone found a way to use a function that the original designer never would have figured somebody would try to use it in that way.

 

Why would anyone decide to create a random distribution where the entire array consists of a single value?  I could use Initialize Array and get the same result.

 

The original designer actually did forsee the possibility that the inputs for MIn and Max would be the same, considered that to be an Error in trying to use the function, and thus output the error code.

0 Kudos
Message 4 of 11
(3,268 Views)

So we have two bugs:

 

  1. The output is NaN if the range is zero. A perfectly valid correct and unique answer exists (all values =1). That should be the result.
  2. The error message talks about the number of samples, which is not the problem here (128>=4 :D)

I agree that both should be documented and fixed. I'll test in 2014.....

 

btw, what is the exact name of the function you are using. I don't see it?

0 Kudos
Message 5 of 11
(3,264 Views)

Black on Blue: Uniform Random.vi

It is found here:

 

Screen Shot 2014-09-25 at 11.27.03.png

 

Continuous Random.vi is actually a Polymorphic VI, one version of it being the uniform distribution.

0 Kudos
Message 6 of 11
(3,237 Views)

altenbach wrote:
  1. The output is NaN if the range is zero. A perfectly valid correct and unique answer exists (all values =1). That should be the result.
  2. The error message talks about the number of samples, which is not the problem here (128>=4 :D)

1. It is part of the Continuous Random VI which is found in the Mathematics->Probability & Statistics->Probability palette.

2. The function just puts out an error code, no description.  The ring inside of the subVI that does this error check states "Invalid Math Domain" (-20069).  When doing a lookup for the error (Help->Explain Error), then you get the weird "samples must be greater than 4" in the explaination.

 

The problem could be fixed by changing the Uniform Inverse CDF.VI to compare to >=0 instead of >0.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 11
(3,235 Views)

OK, found it in vi.lib. Yes, I was actually just suggesting the same solution:

 

 

 

Of course it needs to be verified with all other potential callers to make sure there are no other side effects.

0 Kudos
Message 8 of 11
(3,227 Views)

@altenbach wrote:

OK, found it in vi.lib. Yes, I was actually just suggesting the same solution: 


If only we had the power to make CARs, then we wouldn't need NI at all.  Bug discovery, bug explaination, bug fix, in under an hour.

0 Kudos
Message 9 of 11
(3,196 Views)

In 2015, the CDF VI is not called and a simple rescaling is performed, therefore the NaN output is resolved.

However, if you provide xmin = xmax, LabVIEW stil throws error -20069 and returns an empty array.

This is not the expected behavior. Please fix.

0 Kudos
Message 10 of 11
(2,913 Views)