LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I generate multiple unique random numbers?

Solved!
Go to solution

Hello,

 

I am trying to generate multiple random numbers between a given set of numbers (1-52) and not have the same number generated twice within that set. I can compare the last and next numbers with the compare function but how would I go about comparing all of the generated numbers without using a huge list of shift registers...

 

Any help/ideas are welcome and appreciated.

 

Jason

0 Kudos
Message 1 of 6
(7,987 Views)

Hi JasonPKelly,

    I had attached a vi which will generate a random value between the limits i.e between any numbers.

 

 

 

Thanks and regards,

srikrishnaNF

Regards,
Srikrishna


0 Kudos
Message 2 of 6
(7,986 Views)

Thank You, I was unclear. I can generate the numbers within the set I need. My problem was that I didnt want the same number ever generated again within that set. One idea I had was to build an array each time a random number is generated using the same shift register to pass the number each time and then search the array with the new number. Im going to write that and see if that fixes my problem.

 

Regards,

 

jason

0 Kudos
Message 3 of 6
(7,982 Views)
Solution
Accepted by topic author JasonPKelly

Solved my own problem. Im passing the random number through a shift register each case and building an array each time. I then search the array for the new random number. If the number is not found I get a value of -1, anything else is an index value of 0-whatever. So a greater than (-1) comparer will indicate that the same number is within the array and I can then re-run that case until the same number is not found.

 

Regards,

 

Jason

0 Kudos
Message 4 of 6
(7,968 Views)

You can use mathscript for a very straightfoward approach

rand.jpg    rand1.jpg

0 Kudos
Message 5 of 6
(7,954 Views)

Here is an implementation of Jason's solution.

 

steve

 

random.png

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
Message 6 of 6
(7,943 Views)