LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random distribution of number set

hello all

i would like to create a number list with a predefined amount of specific numbers, but in random order.
now i look for a good idea to realise such a distribution :

i have the numbers 1,2,3,4,5
in 350 appearences i should have:

1 time the 1
2 times the 2
54 times the 3
85 times the 4
200 times the 5

one idea could be to setup an array with all this numbers and its occurences once. then a loop which 350 times randomly select a number, copy this number to a new array (appending) and delete the selected number from the original array. so the new array should have a good mix.

any other good ideas for a realization?

thanks a lot
0 Kudos
Message 1 of 7
(2,725 Views)
I don't quite understand the statement "and its occurrences once", though it sounds like you're talking about creating individual arrays of the specified sizes and then just concatenating them to get your 350-element array. Is this something that you need to be scalable?

Note: By my math 1+2+54+85+200=342, yet you want 350 numbers. What should the other numbers be?
0 Kudos
Message 2 of 7
(2,707 Views)
Just initialize the various sub-arrays, then append them. Now you can use riffle to randomize the element order. 
 
 
0 Kudos
Message 3 of 7
(2,701 Views)
Here's what I had in mind:
 

Message Edited by altenbach on 09-17-2007 10:45 AM

0 Kudos
Message 4 of 7
(2,698 Views)
wow! fantastic 🙂

smercurio... : you are right, the total is not 350....

altenbach: exactly what i have looking for! thanks a lot
0 Kudos
Message 5 of 7
(2,683 Views)
Beware that the Riffle function is not in the Base package.

André
Regards,
André (CLA, CLED)
0 Kudos
Message 6 of 7
(2,666 Views)


andre.buurman@carya wrote:
Beware that the Riffle function is not in the Base package.

If you only have LabVIEW base, you can easily make your own. (based on the fact that arrays of clusters are sorted by element order).

Here's a quick possibility (of course you need to either make it polymorphic or adjust the datatype for your specific situation).


 

Message Edited by altenbach on 09-17-2007 01:35 PM

0 Kudos
Message 7 of 7
(2,659 Views)