Skip to content

Instantly share code, notes, and snippets.

@WhisperingChaos
Last active February 19, 2018 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WhisperingChaos/43a1091ce65512c15472b1441035acea to your computer and use it in GitHub Desktop.
Save WhisperingChaos/43a1091ce65512c15472b1441035acea to your computer and use it in GitHub Desktop.
func consumeOrderedByAffectingProbability(msg_1ch chan msg_1, msg_2ch chan msg_2) {
// implement priorty function that selects messages from msg_2ch twice as often
// as msg_1ch by affecting the probability function of the select
// statement. produces outcome whose message type totals are equivalent to
// nil bias function but using simpler encoding.
for msgCnt := 0; msgCnt < 21; msgCnt++ {
select {
case msg, ok := <-msg_1ch:
if ok {
msg.msgType()
}
case msg, ok := <-msg_2ch:
if ok {
msg.msgType()
}
case msg, ok := <-msg_2ch:
if ok {
msg.msgType()
}
}
}
}
Ordered By Affecting Select Probability Run 1 Ordered By Affecting Select Probability Run 2
msg type 1 msg type 2
msg type 2 msg type 2
msg type 1 msg type 2
msg type 2 msg type 1
msg type 2 msg type 2
msg type 2 msg type 2
msg type 1 msg type 2
msg type 2 msg type 1
msg type 2 msg type 2
msg type 2 msg type 2
msg type 2 msg type 2
msg type 2 msg type 1
msg type 2 msg type 2
msg type 2 msg type 2
msg type 2 msg type 2
msg type 1 msg type 1
msg type 1 msg type 2
msg type 2 msg type 2
msg type 1 msg type 2
msg type 2 msg type 2
msg type 1 msg type 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment