LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random numbers

Solved!
Go to solution

How to generate random binary number "16 bits" ?

0 Kudos
Message 1 of 10
(5,300 Views)

Hi Marina,

 

you use RandomNumber from numerics palette. Then you scale the number to your "16 bits" range as needed…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(5,296 Views)

But it cannot be binary .. I changed it to be unsigned 16 bit inside a loop with constant counter = 15 to be looped 16 times but I got 4 bits I don't know why ! Any Idea ?

 

0 Kudos
Message 3 of 10
(5,292 Views)

Hi Marina,

 

when you run a loop 16 times and only get 4 bits you definitely made something wrong.

 

It would help when you attach your VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(5,286 Views)

here is the VI

0 Kudos
Message 5 of 10
(5,278 Views)
Solution
Accepted by topic author MarinaNashaat

random.png

0 Kudos
Message 6 of 10
(5,270 Views)

If you are asking to have a random unsigned 16bit integer, this will do the trick

 

16bit random.png 

0 Kudos
Message 7 of 10
(5,262 Views)

Thank you 

0 Kudos
Message 8 of 10
(5,259 Views)

Thank you

0 Kudos
Message 9 of 10
(5,258 Views)

Bowen's example will have a slight bias towards zero in any give bit because when the random number is exactly 0.5, it will round down to zero instead of up to 1.  (random number range is 0 to .99999.....)

 

Awang's example is not very good either, actually worse, because it will have a bias away from 0 and 65535 happening about 1/2 as often as the other numbers because the way it rounds to nearest.

 

The proper implementation is to multiply by 65536, then round down.

 

 

 

Message 10 of 10
(5,242 Views)