Hi,

In python there is random. 
<https://docs.python.org/2/library/random.html#random.getrandbits>
getrandbits(*k* 
<https://docs.python.org/2/library/random.html#random.getrandbits>) 
<https://docs.python.org/2/library/random.html#random.getrandbits> 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.

Reply via email to