I need to generate random Uint32 type, I know how to do in int but because of high numbers cause an overflow.
is it possible to generate random Uint32 in min and max range?
I need to generate random Uint32 type, I know how to do in int but because of high numbers cause an overflow.
is it possible to generate random Uint32 in min and max range?
You can just call the standard library:
https://golang.org/pkg/math/rand/#Uint32
To force it within a range, you can use modulu and plus
Example:
func randU32(min, max uint32) uint32 {
var a = rand.Uint32()
a %= (max - min)
a += min
return a
}
on playground: