LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

System Exec.vi calls to %RANDOM% are not random!

Hi all,

 

I just noticed something weird. Is it me or is it System Exec.vi?

 

  1. Make a .bat script that simply has "echo %RANDOM%" in
  2. Call this script from cmd line in windows
  3. See random numbers (0..32767) coming out

Now call the same .bat from System Exec.vi in LabVIEW. The random numbers returned are not random; they increment by 3 every second.

 

What could be causing this? I suspect that System Exec.vi is using some odd form of system time when it generates its random numbers and that this form is different to the one that cmd line uses.

 

Any help or advice is welcome!

 

Max

CLA - Kudos is how we show our appreciation for comments that helped us!
0 Kudos
Message 1 of 3
(1,830 Views)

https://devblogs.microsoft.com/oldnewthing/20100617-00/?p=13673

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 3
(1,817 Views)

Ok, thanks for the link.

 

I think I have figured it out: When I open the cmd window, the random number generator is seeded with the system time. When I call %RANDOM% the first time, the result is not random, it is seeded with the system time. Subsequent calls of %RANDOM% in the same cmd window are then pseudo random, so %RANDOM% is not reseeded.

 

When I make a call to system exec.vi, it is like opening a new cmd window, which results in reseeding of the generator and non-random output. To get a pseudo random output from my bat file using system exec.vi I need to ignore the first return from %RANDOM%.

CLA - Kudos is how we show our appreciation for comments that helped us!
0 Kudos
Message 3 of 3
(1,796 Views)