FAQ
Hi golang-nuts,

I noticed that math/rand.Uint32() uses the high 32 bits of Int63(), after the
sign bit:

     https://github.com/golang/go/blob/c007ce824d9a4fccb148f9204e04c23ed2984b71/src/math/rand/rand.go#L46
     func (r *Rand) Uint32() uint32 { return uint32(r.Int63() >> 31) }

I'm curious if anybody knows why this is the case, instead of just casting
directly to uint32 to get the low 32 bits? Is there some entropy issue with the
low 32 bits?

Code archaeology leads me to this change by rsc being the root of this:

     https://github.com/golang/go/commit/0a097b5cf3648d08af0fcbb38a1fedfa05a12a2b#diff-ff3a03375f3b384d9ccd2d8edc4780daR101

But it's not clear to me why the implementation changed at the same time as the
names.

Thanks,
Aaron

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 20 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 15, '15 at 1:15a
activeMay 18, '15 at 1:20p
posts20
users10
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase