07-23-2012 05:24 AM
The "dice" function in LabVIEW is ised to generate random numbers between 0 and 1. If I create an array[100000] with random numbers between 0 and 100, the occurance of 1 to 100 is the same (about 1000 times each), but the occurance of 0 is only 500.
So my question is, on which basis will random numbers generated?
Solved! Go to Solution.
07-23-2012 05:33 AM
http://digital.ni.com/public.nsf/allkb/9D0878A2A596A3DE86256C29007A6B4A
-CC
07-23-2012 05:44 AM - edited 07-23-2012 05:49 AM
Hi mitu,
it's not a problem of the RNG, it's a problem of your rounding function!
You use "To U8" to convert the random DBL to an integer. ToU8 rounds to the next integer. So all number from 0-0.5 will get rounded to 0, but all numbers from 0.5 to 1.5 will get rounded to 1. So you have twice the range of numbers rounded to 1 than the range for rounding to zero - the same applies for your "end of range" with rounding to 100. 100 should also have less probability (in your VI) to appear...
To get same probability you should (explicitely) round downwards before converting to U8!
Btw. you could also search the forum to get the same answer by searching for "random probability"...
07-23-2012 05:50 AM - edited 07-23-2012 05:58 AM
As GerdW mentioned, it is a function of the way you are rounding.
There is a discussion on the LAVA forums that describes how to generate a random array of numbers with equal distribution.
http://lavag.org/topic/14981-random-number-integer-numeric-package/page__view__findpost__p__90015