LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how random numbers will be generated

Solved!
Go to solution

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?

 

 

Download All
0 Kudos
Message 1 of 4
(3,508 Views)

http://digital.ni.com/public.nsf/allkb/9D0878A2A596A3DE86256C29007A6B4A

 

-CC

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


Message 2 of 4
(3,502 Views)
Solution
Accepted by mitulatbati

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"...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 4
(3,492 Views)

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

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 4
(3,483 Views)