package crypto
import (
"io"
"github.com/gotd/td/bin"
)
func RandInt64n (randSource io .Reader , n int64 ) (int64 , error ) {
v , err := RandInt64 (randSource )
if err != nil {
return 0 , err
}
if v < 0 {
v *= -1
}
return v % n , nil
}
func RandInt64 (randSource io .Reader ) (int64 , error ) {
var buf [bin .Word * 2 ]byte
if _ , err := io .ReadFull (randSource , buf [:]); err != nil {
return 0 , err
}
b := &bin .Buffer {Buf : buf [:]}
return b .Long ()
}
func RandInt128 (randSource io .Reader ) (bin .Int128 , error ) {
var buf [bin .Word * 4 ]byte
if _ , err := io .ReadFull (randSource , buf [:]); err != nil {
return bin .Int128 {}, err
}
b := &bin .Buffer {Buf : buf [:]}
return b .Int128 ()
}
func RandInt256 (randSource io .Reader ) (bin .Int256 , error ) {
var buf [bin .Word * 8 ]byte
if _ , err := io .ReadFull (randSource , buf [:]); err != nil {
return bin .Int256 {}, err
}
b := &bin .Buffer {Buf : buf [:]}
return b .Int256 ()
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .