LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulating the rolling of a dice

Solved!
Go to solution

I want to create a program that simulates the rolling of one dice. Does this code work to simulate that effect?

IMG_6522.jpg

 

0 Kudos
Message 1 of 15
(6,734 Views)

Hello,

Yes it'll work very well. The result will be a number between 1..6

Best Regards,
Applications Engineer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
CLAD // CLD
0 Kudos
Message 2 of 15
(6,713 Views)

What will happen when the random number primitive generates a very small number, say 0.05?

Matt J | National Instruments | CLA
0 Kudos
Message 3 of 15
(6,709 Views)

Yess the example will have as result 0  sorry i have not pay attention. But we can change the code as shown in the figures:

 

Best Regards,
Applications Engineer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
CLAD // CLD
Download All
0 Kudos
Message 4 of 15
(6,689 Views)

No, it will not work. As was hinted by Jacobson it will generate a number between 0 and 6, not the desired 1 and 6. Change your rounding to Round toward + infinity and it will work.

 

Edited to add: 

 

Your last post came while I was typing. I believe that your second approach will be biased such that 6 will be half as likely as 2 - 5 and you will be 50% more likely to have a value of 1.

Message 5 of 15
(6,686 Views)

@REFNH wrote:

Yess the example will have as result 0  sorry i have not pay attention. But we can change the code as shown in the figures:

 


As mentioned below, round to + infinity is what you really want to do. Your strategy will only generate numbers 1..6 but if you plot the distribution of the outputs you will see an issue. In your example, 1 will appear if RAND*6 is between 0 and 1.5 while 6 will only appear if RAND*6 is between 5.5 and 6.0

Matt J | National Instruments | CLA
Message 6 of 15
(6,670 Views)

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

Best Regards,
Applications Engineer
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
CLAD // CLD
0 Kudos
Message 7 of 15
(6,665 Views)

Here's how I simulated rolling a die with animation

 

Die.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 15
(6,643 Views)

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.


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 9 of 15
(6,640 Views)

@RTSLVU wrote:

Here's how I simulated rolling a die with animation

 

Die.png


I've not yet installed LV2019 but I believe that your die is biased. Both 1 and 6 will be half as likely as any other number (You'll only get 1 for values of 1 to 1.49, 2 for values of 1.5 to 2.49, . . . , 6 for values of 5.5 to 6).

0 Kudos
Message 10 of 15
(6,605 Views)