LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dice Frequency

Solved!
Go to solution

Hi everyone.

 

I am trying to perform some statistical analysis on an array of dice rolls. 

 

As can be seen from the image below, I habe successfully produced a series of random dice rolls, with the user specifying the number of dice rolls desired. It is output as an array. I am trying to calculate the frequency of each dice roll, e.g. the frequency of 1s, 2s, 3s etc. I am currently struggling. I tried using the histogram VI. Any suggestions?

 

Dice Error.png

0 Kudos
Message 1 of 12
(5,616 Views)

We can't offer any suggestions until you tell us in what ways you are struggling.

0 Kudos
Message 2 of 12
(5,606 Views)

Well as you can see, the histogram values are splitting into decimal values rather than a 1, 2, 3 etc. 

 

The problem comes from the fact that you don't always roll a 1 and a 6. If I set the bin number to constant 6, and then only end up with 3s and 4s, , it thinks it needs to split those 3s and 4s across 6 sections between 3 and 4.

 

In the example image I posted, I have 6 histogram points but they are all between 3 and 6. 

 

The array histogram h(x) starts with a 1, yet I have 0 1s. It then has 3 zeroes, yet the third value should be a 1 as I have one 3. The 3 and 2 look ok since I have 2 sixes and 3 fives.

 

There are 6 indicators on the right of the code, and I am trying to display the frequency of each dice face in the relevant indicator.

0 Kudos
Message 3 of 12
(5,602 Views)

Actually, I can't see because the image is just small enough that it is hard to tell what is going on.  In general, the code looks pretty good.  I can't guess at all the things that might be causing you problems.  If you are looking for help, then it is helpful if you tell us where you need help.Smiley Wink  Attaching the actual VI can help as well because than we can see and poke around in it.  And even run it to see how it is behaving.

 

There are several histogram functions in LabVIEW.  One of them, has more control of how the bins are set up.  It is called General Histogram.vi

 

You may want to wire a 6 into that histogram rather than connecting it to the number of rolls.  If you had 100 rolls, you wouldn't want a 100 bins.

0 Kudos
Message 4 of 12
(5,585 Views)

Ok sorry yeah, I use a massive monitor so forgot otehr people might not be able to see as clearly.

 

I didn't want to attach the code as it has sub-VIs and sub-sub-VIs so would be a pain to attach everything. Whats the best way to make sure you get all the sub-VIs as well. Do I need to go through the code and find every sub-VI individually and attach them?

 

I've done that on this occasion

Download All
0 Kudos
Message 5 of 12
(5,573 Views)
One thing that I can see is that you are using DBLs. Use integers.
0 Kudos
Message 6 of 12
(5,568 Views)

Regarding number of Bins, I did try a 6 constant but the data doesnt always have a 1 and 6 in there. Then it messes the code up because it makes 6 divisions out of 5 subsets so you end up with 3.2, 4.6 etc.

 

my most recent version I maximum and minimum values in my array and tried to use that to calculate the number of bins I need. I tried subtracting the upper from the lower, when that didnt work I tried adding one to it, it hasn't worked as of yet

 

Dice error 2.png

0 Kudos
Message 7 of 12
(5,561 Views)

Here is an example with a 6 constant. As you can see, because there are only 2 -6, it tries to split 5 possible values across 6 bins so I end up with weird values in my histogram and x-values

 

Dice error 3.png

0 Kudos
Message 8 of 12
(5,554 Views)

For attaching all, there is an option in the build specifications on a project to build a source distribution.

 

It is also helpful to zip them up.  It is easier to upload and download, and the forums are limited to 3 file attachments per message.

 

I modified your VI to use the general histogram.

 

In your dice roll VI.  You should be using 5 as your multiplier rather than 4.99.  Otherwise you'd be slightly biasing your results towards the lower numbers.  Actually, you are never getting a 1 unless you happen to get lucky and get an exact  0.00000..... because anything above that rounds up to 1, then you add 1 giving you a two.

 

The correct randomization for a dice roll.   Is random  Times 6.  Round down,  Add 1.

Message 9 of 12
(5,547 Views)

Ok brilliant. I have put the last few finishing touches in and this time saved it as a zip file. Could you double check it for me and give me any critique as to how I can improve my code?

0 Kudos
Message 10 of 12
(5,514 Views)