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.
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.
12-21-2012 02:32 AM
I have an array of length less than 10. The elements are integers between 0 and 50.
I want to generate a random number between 0 and 50 (all integers) excluding those in the array.
How do I do this in labview.
Thanks.
12-21-2012 03:32 AM - edited 12-21-2012 03:33 AM
But I'm not sure if this is what you mean.
Christian
12-21-2012 03:41 AM - edited 12-21-2012 03:50 AM
The code by Christian will have a smaller probability for the values 0 and 50 than for the other numbers. Your range covers 51 numbers so you have to multiply the random number by 51, then subtract 0.5 before rounding.
Also, it does not check if the number is in the array.
You could do something like this.
12-21-2012 03:44 AM
This program generates nine random numbers andfill them in an array. But I didn't mean this.
I have an array A of nine elements whose elements are integers between 0 and 50.
I want to generate only one random number between 0 and 50 which doesn't match elements in A.
Thanks
12-21-2012 03:48 AM
12-21-2012 03:49 AM - edited 12-21-2012 03:51 AM
12-21-2012 03:51 AM
12-21-2012 03:55 AM
Christian, your are still not generating integers (blue) and your random number are still not really random, because 0 and 50 only occur with half the probability of the other numbers. You would get fired from any casino in Vegas!. 😄
You need to multiply by 51 the round to -infinity as in my example above.
12-21-2012 03:55 AM
12-21-2012 03:57 AM
@mikeporter wrote:
The problem with your example Christian is that you are comparing floating point values for equality - which will not always give you the result you are expecting..
After rounding to nearest, we should be safe here. 😉