LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to count number of occurrences

Hello all,

 

I am new to Labview and programming in general.

 

I am making a simple VI that simply simulates a roll of a dice and then outputs how many times the dice fell on a particular value (1-6).

The input is the amount of times the dice is to be rolled, which I know is simply the number wired to the count terminal of a for loop. I used the random number generator multiplied by 6 and rounded to next highest integer to get numbers between 1 and 6, but how do I record how many times a number occurred for each iteration? I believe I should use 6 numeric indicators for the outputs?

 

Do I need to use a shift register?

 

Thanks

 

 

0 Kudos
Message 1 of 3
(4,896 Views)

Yes.  Shift registers will keep the counts going between iterations of the loop.

 

I'd recommend an array rather than 6 different indicators and shift registers.  Use Replace Array Subset to increase a particular element of the array by 1.

 

For random numbers from 1 to 6 evenly distributed,.you should multiply by 6, round down to the nearest integer, then add 1.  By rounding up, 1 would have a slightly higher chance of occurring than 2 through 5, and 6 would have a slight lower chance than 2 through 5.

Message 2 of 3
(4,882 Views)

RavensFan wrote: Use Replace Array Subset to increase a particular element of the array by 1.

An array would definately be the best route to go with this.  It's a little more advanced, but I would use the Inplace Element Structure to increment your values.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 3
(4,846 Views)