LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulating the rolling of a dice

Solved!
Go to solution
Solution
Accepted by ef99

@RTSLVU wrote:

Here's how I simulated rolling a die with animation

 

Die.png


NO NO NO.

 

The correct implementation of a random number generator is to multiply by the number of different things you want and round DOWN.  So mutltiply by 6, and round down will give you a number between 0 and 5 each with an equal chance of occurring.  Since this is a die, you will add 1 to the result to give you a number from 1 to 6.

 

Look at the difference in distribution of the numbers.  With the image in this post, the numbers 1 and 6 only happen about half as often as they should.

 

0 Kudos
Message 11 of 15
(2,648 Views)

@crossrulz wrote:

If you are using LabVIEW 2019, just use the Random Number (Range).vi.

EDIT: You will want to use the U64 or I64 version, not the DBL.


This is cool. It may be time to install 2019.

0 Kudos
Message 12 of 15
(2,644 Views)

@RavensFan wrote:


NO NO NO.

 

The correct implementation of a random number generator is to multiply by the number of different things you want and round DOWN.  So mutltiply by 6, and round down will give you a number between 0 and 5 each with an equal chance of occurring.  Since this is a die, you will add 1 to the result to give you a number from 1 to 6.

 

Look at the difference in distribution of the numbers.  With the image in this post, the numbers 1 and 6 only happen about half as often as they should.

 


Ah well I was mainly trying to show off my animation, I never really thought about the random number generation.  

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 13 of 15
(2,640 Views)

@REFNH wrote:

if we want that the probability is the same for all the numbers we can use a while loop 


A while loop does not generate random numbers and your code still gives unequal probabilities. Did you even test?

 

(You could fix the probability issues by multiplying by 6.5 instead of six, but there is no justification for such convoluted code if better alternatives exist. See below.)

0 Kudos
Message 14 of 15
(2,635 Views)

While the help states that 0 is a possible outcome, this is actually incorrect as has been discussed elsewhere.

So, to get numbers 1..6, all we need to do is round towards +inf. No need for the +1.

 

As you can see, the code that was incorrectly marked as solution (above) still only give half the probability (or even less chance to get boxcars with two dice! You do the math!) With code like that, you'll never get a job in Vegas (top code in picture) :D.

 

Here's all we need for a fair dice (bottom code):

 

RandomDice.png

 

 

0 Kudos
Message 15 of 15
(2,613 Views)