Re: [go-nuts] How to generate long int with k random bits.

2017-10-13 Thread Jan Mercl
> On Fri, Oct 13, 2017 at 4:37 PM Christian LeMoussel 
wrote:

See https://golang.org/pkg/math/big/#Int.Rand

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] How to generate long int with k random bits.

2017-10-13 Thread Christian LeMoussel
Hi,

In python there is random. 

getrandbits(*k* 
) 
 that returns 
a python long int with *k* random bits. 
Eg : getrandbits(128) => long int with 128 random bits

I do this

func init() {
rand.Seed(time.Now().UnixNano())}
var bitsRunes = []rune("01")

func RandBitsRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = bitsRunes [rand.Intn(len(bitsRunes ))]
}
return string(b)}


i,_ := strconv.Btoi64(RandBitsRunes(128), 2)


I'm new in Go.  There may be a more efficient solution


Thank for your help.



-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.