dice.Roll()

This commit is contained in:
v2ray
2016-01-21 22:45:44 +01:00
parent d623b1809d
commit 37a9d8ef50
6 changed files with 23 additions and 36 deletions
+4 -20
View File
@@ -1,10 +1,10 @@
package outbound
import (
"math/rand"
"sync"
"time"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
@@ -44,12 +44,7 @@ func (this *Receiver) AddUser(user *vmess.User) {
}
func (this *Receiver) PickUser() *vmess.User {
userLen := len(this.Accounts)
userIdx := 0
if userLen > 1 {
userIdx = rand.Intn(userLen)
}
return this.Accounts[userIdx]
return this.Accounts[dice.Roll(len(this.Accounts))]
}
type ExpiringReceiver struct {
@@ -108,11 +103,7 @@ func (this *ReceiverManager) pickDetour() *Receiver {
return nil
}
this.detourAccess.RLock()
idx := 0
detourLen := len(this.detours)
if detourLen > 1 {
idx = rand.Intn(detourLen)
}
idx := dice.Roll(len(this.detours))
rec := this.detours[idx]
this.detourAccess.RUnlock()
@@ -129,14 +120,7 @@ func (this *ReceiverManager) pickDetour() *Receiver {
}
func (this *ReceiverManager) pickStdReceiver() *Receiver {
receiverLen := len(this.receivers)
receiverIdx := 0
if receiverLen > 1 {
receiverIdx = rand.Intn(receiverLen)
}
return this.receivers[receiverIdx]
return this.receivers[dice.Roll(len(this.receivers))]
}
func (this *ReceiverManager) PickReceiver() (v2net.Destination, *vmess.User) {
+2 -6
View File
@@ -1,7 +1,7 @@
package vmess
import (
"math/rand"
"github.com/v2ray/v2ray-core/common/dice"
)
type UserLevel byte
@@ -39,11 +39,7 @@ func (this *User) AnyValidID() *ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
if len(this.AlterIDs) == 1 {
return this.AlterIDs[0]
}
idx := rand.Intn(len(this.AlterIDs))
return this.AlterIDs[idx]
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
type UserSettings struct {