LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Random Numbers

Solved!
Go to solution

I generate random numbers (20 of them) and write them to output file.

It works fine (all 20 numbers are different) but everytime I run the program it outputs the same set of random numbers.

 

num1 = Random (1, 999);
num2
= Random (1, 999);

 

I need a new set of random numbers everytime I run the program. How do I do t

 

 

0 Kudos
Message 1 of 3
(3,140 Views)
Solution
Accepted by topic author CVI_User123

You must initialize the random number generator to a different value each time so that the sequence of (pseudo)random numbers is different. The function to use is SetRandomSeed. A simple way to initialize it each time with a different seed is to use the timer: SetRandomSeed (0);



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,139 Views)

Yes, that works,

 

Thanks.

0 Kudos
Message 3 of 3
(3,136 Views)