09-09-2019 10:04 AM
I want to create a program that simulates the rolling of one dice. Does this code work to simulate that effect?
Solved! Go to Solution.
09-09-2019 10:22 AM
Hello,
Yes it'll work very well. The result will be a number between 1..6
09-09-2019 10:23 AM
What will happen when the random number primitive generates a very small number, say 0.05?
09-09-2019 10:39 AM
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:
09-09-2019 10:40 AM - edited 09-09-2019 10:45 AM
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.
09-09-2019 10:46 AM
@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
09-09-2019 10:50 AM
if we want that the probability is the same for all the numbers we can use a while loop
09-09-2019 11:11 AM - edited 09-09-2019 11:17 AM
Here's how I simulated rolling a die with animation
09-09-2019 11:12 AM - edited 09-09-2019 11:15 AM
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.
09-09-2019 12:16 PM - edited 09-09-2019 12:19 PM
@RTSLVU wrote:
Here's how I simulated rolling a die with animation
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).