Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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

(fixed playground link)



You'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


So it's deterministic. I got the same numbers.


On the Playground or on your PC? The Playground has an execution cache, so the same input code always gives the same (thus "deterministic") result.


Ah OK, it was on the playground. Is it deterministic when not cached?


It is not deterministic on playground if it is not cached.

You can add dummy code to the file to break free from the cache.


Adding some white space also does the trick




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: