Browse Source

Add Int31n() and RandInt31n().

pull/1780/head
Thomas Corbière 7 years ago
parent
commit
d66d43d2ea
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      common/random.go

+ 12
- 0
common/random.go View File

@ -93,6 +93,10 @@ func RandInt31() int32 {
return grand.Int31()
}
func RandInt31n(n int32) int32 {
return grand.Int31n(n)
}
func RandInt63() int64 {
return grand.Int63()
}
@ -224,6 +228,14 @@ func (r *Rand) Int31() int32 {
return i31
}
// It is not safe for cryptographic usage.
func (r *Rand) Int31n(n int32) int32 {
r.Lock()
i31n := r.rand.Int31n(n)
r.Unlock()
return i31n
}
// It is not safe for cryptographic usage.
func (r *Rand) Int63() int64 {
r.Lock()


Loading…
Cancel
Save