04-17-2013 01:34 PM
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.
04-17-2013 01:38 PM
@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.
04-17-2013 01:46 PM
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
04-17-2013 02:02 PM
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/
04-17-2013 02:03 PM
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.
04-17-2013 02:21 PM - edited 04-17-2013 02:22 PM
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.
04-17-2013 02:33 PM
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.
04-17-2013 03:00 PM
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
04-17-2013 03:05 PM
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
04-17-2013 03:23 PM
@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.