4 ms·
I thought an "interesting" part of the change was actually how they made a 50% chance work for the extra read. They select across a closed channel twice -- and
by pquerna 8y ago
I thought an "interesting" part of the change was actually how they made a 50% chance work for the extra read. They select across a closed channel twice -- and it results in a mostly even distribution of chance.
for i := 0; i < 100000; i++ {
select {
case <-closedChan:
a++
case <-closedChan:
b++
case <-closedChan:
c++
case <-closedChan:
d++
}
}
Results in an almost even distribution across the select choices!
https://play.golang.org/p/cnAXBEZJm2B https://play.golang.org/p/cnAXBEZJm2B
(fixed playground link)
- zimpenfish 8y agoYou're printing `b` three times in that Playground which makes it a look skewed. a: 25100 b: 25080 c: 25080 d: 25080 vs a: 24973 b: 25010 c: 25013 d: 25004
- cup-of-tea 8y agoSo it's deterministic. I got the same numbers.
- akavel 8y agoOn the Playground or on your PC? The Playground has an execution cache, so the same input code always gives the same (thus "deterministic") result.
- cup-of-tea 8y agoAh OK, it was on the playground. Is it deterministic when not cached?