From 1a1383c2ea947886384a928101d3d1aae36b5ba4 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Fri, 18 Nov 2016 21:34:42 +0100 Subject: [PATCH] simplify random --- transport/internet/udp/hub.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/transport/internet/udp/hub.go b/transport/internet/udp/hub.go index a0fdf295..6eea8668 100644 --- a/transport/internet/udp/hub.go +++ b/transport/internet/udp/hub.go @@ -41,15 +41,16 @@ func NewUDPPayloadQueue(option ListenOption) *UDPPayloadQueue { func (this *UDPPayloadQueue) Enqueue(payload UDPPayload) { size := len(this.queue) + idx := 0 + if size > 1 { + idx = dice.Roll(size) + } for i := 0; i < size; i++ { - idx := 0 - if size > 1 { - idx = dice.Roll(size) - } select { - case this.queue[idx] <- payload: + case this.queue[idx%size] <- payload: return default: + idx++ } } }