LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulation of a dice

Solved!
Go to solution

Hello

I want to simulate a dice, but the tricky part is that i want to stop it after a user defined number (between 1-6) appears a user defined number in a row. Does anybody know how i should do this?

 

I hope it make sense

 

- Michael

0 Kudos
Message 1 of 14
(391 Views)

Hi Michael,

 


@MSK97 wrote:

I want to simulate a dice, but the tricky part is that i want to stop it after a user defined number (between 1-6) appears a user defined number in a row. Does anybody know how i should do this?


Yes.

Spoiler
Use a loop. Count how often that "user defined number" occurs in the dice rolls. Stop the loop once you reached your "numbers in a row".

You need a while loop, a shift register, a comparison function, a select function, an increment and a zero constant and one more comparison function.

What have you tried so far and where are you stuck?

You know this forum is not intended to solve your homework!

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 2 of 14
(388 Views)

Since you have only the "tricky part" left, can we assume that your dice simulation is finished otherwise? Do you have two controls, one to define the desired outcome number and one to define the number of occurrences in a row? Do you have a loop that repeats the trial until the condition is met? Do you have a mechanism to count the number of successive occurrences of the selected value? (hint: shift register!) Do you have a way to reset that number whenever the wrong dice number occurs? Do you have indicators for interesting statistics and updates to keep the user informed (e.g. for the total number of tries so far? the longest sequence so far? the total elapsed time? etc.).

 

Feel free to attach what you have accomplished so far and explain where you got stuck and we might be able to point you in the right direction.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 3 of 14
(381 Views)

Hi.

Thank you for your answer.

 

I am quite new to Labview, but i love to learn, and i actually like the program. I think i can finish the job, whenever i find a way to count the number of successive occurrences of the selected value. 

To answer some of your question: Yes, i have a iteration counter and a time counter for how long it will take to finish the task. I have attached what i have so far. I know its not that good, but im learning 🙂 

0 Kudos
Message 4 of 14
(308 Views)
Solution
Accepted by topic author MSK97

OK:

 

  • Your two controls need to be integers (blue, not orange)
  • To record numbers in the range 1--6, U64 is overkill, but that's what the subVI puts out, so it's OK. 😄
  • Always append to an array. You are prepending the new element which is much harder on the memory manager and much less efficient. You actually don't need any arrays at all, just keep count of successive matches. Initialize the shift register with a scalar zero.
  • If the number for times in a row is large, the probability is infinitely small, so restrain that input too.
  • Once you set the max and min values, it will be stored with the VI. No need to set it every time the VI runs. These property nodes are only needed if the ranges need to be changed at runtime. (Also, a property node is resizable, no need for two).
  • You already do a comparison, so add a case structure and wire it to the boolean. Use a +1 inside the true case, and leave the false case empty, with the output tunnel set to "use default if unwired".
  • After the case structure check if the value in the shift register matches the "number of times in a row" and stop the loop if that happens.

See how far you get. You are almost there!


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 5 of 14
(303 Views)

Here's how it could look like:

 

altenbach_1-1621186980830.png

 

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 6 of 14
(257 Views)

Hi

 

Thank you very much. I made it with your explanation, so it doesnt quite look as good as yours, but im glad that i could make it 🙂 

Message 7 of 14
(240 Views)

Just an FYI - "dice" is plural for "die".  Strange, but true.  ("Die" can mean about 400 different things.  Yeesh.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 14
(213 Views)

@billko wrote:

Just an FYI - "dice" is plural for "die".  Strange, but true.  ("Die" can mean about 400 different things.  Yeesh.)


From here:

 

"The singular usage is considered incorrect by many authorities. However, it should be noted that The New Oxford Dictionary of English, Judy Pearsall, Patrick Hanks (1998) states that “In modern standard English, the singular die (rather than dice) is uncommon. Dice is used for both the singular and the plural.”

 

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 9 of 14
(205 Views)

@altenbach wrote:

From here:

 

"The singular usage is considered incorrect by many authorities. However, it should be noted that The New Oxford Dictionary of English, Judy Pearsall, Patrick Hanks (1998) states that “In modern standard English, the singular die (rather than dice) is uncommon. Dice is used for both the singular and the plural.”


Tell that to every single child's game I have been playing for the last 6 years.  I have yet to see "dice" refer to the singular in the instructions (yes, this is something I watch).  It is always "throw the die."


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
Message 10 of 14
(196 Views)