LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Coin Toss Simulator

You misunderstand how shift registers work. You can easily eliminate the use of the local variable even though it's in two different cases. Put the shift register around the for loop, tunnel the wire into the case structure, modify the value on the wire as necessary, tunnel the value out again and back to the other side of the shift register.

 

Perhaps a better suggestion would be, "Rewrite your code so that you never read from a local variable of an indicator." This you can definitely do.

0 Kudos
Message 11 of 92
(1,316 Views)

@Edjsch wrote:

Doesn't seem to help. The first time there was a pop-up (I think from NI) to allow installation of an add on. I said yes. Don't know what the problem is. I've added attachments before without any problems. Maybe I'll try Google Chrome.

 

Ed


There has been a problem with the forums lately working with IE8.  See Problem uploading attachments.

0 Kudos
Message 12 of 92
(1,313 Views)

Thanks, but how do I "modify the value on the wire"? Can you post a screen shot?

 

Also, feedback nodes are identical to shift registers, with less less "wiring" to clutter up the code. So maybe you can show an example with this, too.

 

But, as I said, the sequence structure indicates that the problem is NOT a race condition. Your thoughts?

 

Thanks,

Ed

0 Kudos
Message 13 of 92
(1,308 Views)

I could not follow the logic with all of the locals so I rewrote it...

Funny enough I am getting the same numbers (around 40%).

 

Which made me think your math must be faulty.  This web site is fairly interesting.  My guess, without doing the math, is that 10 consecutive trues only occures 40% of the time with a set of 1024.

http://marknelson.us/2011/01/17/20-heads-in-a-row-what-are-the-odds/

 

New Bitmap Image.png

 

0 Kudos
Message 14 of 92
(1,294 Views)

Here's your VI with some of the local variables replaced with shift registers, the rest are left as an exercise.

 

I noticed running your VI that I got a negative number for Heads, because you're using a 16-bit integer and it wraps around. You might consider using a larger datatype, I wonder if that's part of your problem.

0 Kudos
Message 15 of 92
(1,294 Views)

I was with Don.  I just rewrote most of the inside FOR loop using shift registers.  I also had some feedback nodes to help track streaks.  I found that a tail will occurs about 50% of the time after 10 consecutive heads.

EDIT:  Just noticed that I need a 1 minus after the division.  But you get the point.


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 16 of 92
(1,280 Views)

I just put my above code into another FOR loop to run 1000 times and I got ~500 streaks of >=10 with N set to 1024.


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 17 of 92
(1,272 Views)

crossrulz,

 

Thanks. You said, "I was with Don" which I take to mean that either 1) my "math must be faulty" or 2) "doing the math, is that 10 consecutive trues only occures 40% of the time with a set of 1024". But then you said you, "got ~500 streaks of >=10 with N set to 1024", which says that the latter (2) of the above assumption is not correct. That means that my math must be faulty.

 

Do you see the error?

 

BTW, maybe the code with the block diagram with shift registers and feedback nodes is "better" but it LOOKS much more complicated than with local variables, IMHO. No?

 

Ed

0 Kudos
Message 18 of 92
(1,260 Views)

Crossrulz,

 

Also can you post your final code? If you can post it for LV version 8.5 that would be great, otherwise I'll post it for a down-convert. Thanks.

 

Ed

0 Kudos
Message 19 of 92
(1,259 Views)

@Edjsch wrote:

crossrulz,

 

Thanks. You said, "I was with Don" which I take to mean that either...


Actually, I meant that the code was too complicated and I needed to totally rewrite it.  I really think your problem is the local variables.  They add all kinds of headaches just because you don't know exactly when they will execute.  I could rewrite the code to be a little easier to read by using case structures, but I prefer showing the full amount of code.  And I think my code looks simpler for the reason of the locals and embedded structures make things harder to read.


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 20 of 92
(1,248 Views)